<java> pb avec ce prg "scanner"

domxaline -  
 biboo -
Bonjour,
j'ai essayé ce prg qui suit,en le executant dans le console du eclipse s'affiche une erreur message

java.lang.NoSuchMethodError: main
Exception in thread "main"

comment je dois arranger cde prg,m'aidez s'il vous plaît

import condition.Scanner;
public class whi
//Une variable vide
String prenom;
// On initialise celle-ci à O pour oui !
char reponse = 'O';
//Notre objet Scanner, n'oubliez pas l'import de java.util.Scanner
java.util.Scanner sc = new java.util.Scanner(System.in);
//Tant que la réponse donnée est égale à oui
while (reponse == 'O')
{

//On affiche une instruction
System.out.println("Donnez un prénom : ");
//On récupère le prénom saisi
prenom = sc.nextLine();
// On affiche notre phrase avec le prénom
System.out.println("Bonjour " +prenom+ " comment vas-tu ?");
//On demande si la personne veut faire un autre essai
System.out.println("Voulez-vous réessayer ?(O/N)");
//On récupère la réponse de l'utilisateur
reponse = sc.nextLine().charAt(0);
}

System.out.println("Au revoir...");
//Fin de la boucle
Configuration: Windows XP Internet Explorer 6.0

3 réponses

  1. domxaline
     
    j'ai modifié le prg comme ceci,maintenant j'ai un message suivant:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Scanner cannot be resolved to a type

    at whi.main(whi.java:10)
    et la dans la ligne java.util.Scanner sc=new Scanner(System.in);
    le mot Scanner est souligné
    et dans la ligne System.out.println("Au revoir...");
    le point qui se trouve après out et le phrase "Au revoir..." sont soulignés

    public class whi
    {
    public static void main(String args[])
    {
    String prenom;
    char reponse = 'O';
    java.util.Scanner sc=new Scanner(System.in);
    while (reponse == 'O')

    System.out.println("Donnez un prénom : ");
    prenom = sc.nextLine();
    System.out.println("Bonjour " +prenom+ " comment vas-tu ?");
    System.out.println("Voulez-vous réessayer ?(O/N)");
    reponse = sc.nextLine().charAt(0);
    }
    System.out.println("Au revoir...");
    }
    0
  2. domxaline
     
    j'ai modifié le prg ainsi:

    import java.util.Scanner;
    public class whi
    {

    public static void main(String[] args)

    {
    String prenom;
    char reponse = 'O';
    Scanner sc=new Scanner(System.in);
    while (reponse == 'O')

    System.out.println("Donnez un prénom : ");
    prenom = sc.nextLine();
    System.out.println("Bonjour " +prenom+ " comment vas-tu ?");
    System.out.println("Voulez-vous réessayer ?(O/N)");
    reponse = sc.nextLine().charAt(0);

    System.out.println("Au revoir...");
    }

    }

    maintenant le prg execute,mais la ligne
    Donnez un prénom :
    defile sans s'arrêter,
    maintenant comment je l'arrête et taper le prénom
    0
  3. biboo
     
    Tu as oublié les accolades de ton while( ).
    Si tu n'indiques pas le périmètre d'action de ton while ( while ( ce que tu veux ) { // TO DO } ), il va afficher uniquement l'instruction après le while à l'infini.

    Dans ton cas, il affichera donc à l'infini :

    Donnez un prénom : 


    Ce qui est le cas n'est-ce pas?
    0