Unresolved compilation problem:

cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 24 août 2009 à 15:50
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 - 25 août 2009 à 09:07
Bonjour,
voilà j'ecris le programme suivant
package Mypackage;
import java.util.Scanner;
public class exercjavascanne
{ 	
   public static void main(String[]args) 
   {
    String[]tab={"Simon","Chris","David","Sarko","Sego","Hardy","Patrick","Franck","Samir"};
    Scanner sc=new Scanner(System.in);
    System.out.print("Entrez un nom:");
    String nom=sc.nextString();
    String reponse="Ce nom ne se trouve pas dans notre system";
     for(int i=0;i<tab.length;i++)
    	 if(tab[i].equals(nom))
    	 {
    		 reponse="Ce nom se trouve dans notre system;";
    		 break;
    	 }
   }
    System.out.print(reponse);
}


dans les phrases :
String nom=sc.nextString(); 

next string souligné
System.out.print(reponse); 

.out et reponse souligné

en compilant mon programme j'ai un message
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextString() is undefined for the type Scanner

at Mypackage.exercjavascanne.main(exercjavascanne.java:10)

(exercjavascanne.java:10)// String nom=sc.nextString();

veuillez m'aidez s'il vous plaît

12 réponses

cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
24 août 2009 à 16:15
j'ai changé nextString pour nextLine,ligne rouge est parti et compilé
maintenant j'ai message suivant
Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at Mypackage.exercjavascanne.main(exercjavascanne.java:5)

(exercjavascanne.java:5)//public static void main(String[]args)


System.out.print(reponse);
.out et reponse toujours souligné
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
24 août 2009 à 17:05
j'ai corrigé mon programme ainsi:
package Mypackage;
import java.util.Scanner;
public class exercjavascanne
{ 	
   public static void main(String[]args) 
   {
    String[]tab={"Simon","Chris","David","Sarko","Sego","Hardy","Patrick","Franck","Samir"};
    Scanner sc=new Scanner(System.in);
    System.out.print("Entrez un nom:");
    String nom=sc.nextLine();
    String reponse="Ce nom ne se trouve pas dans notre system";
     for(int i=0;i<tab.length;i++)
      { 
       if(tab[i].equals(nom))
    	 {
    		 reponse="Ce nom se trouve dans notre system;";
    		 break;
    	 }
     }
   }
    System.out.print(reponse);
}

maintenant dans la ligne:
System.out.println(reponse);


println souligné
0
kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 7
24 août 2009 à 17:55
Salut,

essaie en ajoutant un espace entre String[] et args dans
public static void main(String[] args) 
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
24 août 2009 à 18:00
rien à changer
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
kirua12 Messages postés 1155 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 29 avril 2011 7
24 août 2009 à 18:02
ah, je l'avais pas vu avant, ton instruction est en dehors de la méthode main donc c'est normal que le compilo n'aime pas.
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
24 août 2009 à 18:15
que je dois faire?
0
Utilisateur anonyme
24 août 2009 à 19:40
Salut,

for(int i=0;i<tab.length;i++)
      { 
       if(tab[i].equals(nom))
    	 {
    		 reponse="Ce nom se trouve dans notre system;";
    		 break;
    	 }
     }
   }
    System.out.print(reponse); 
} 


A modifier comme ceci:

for(int i=0;i<tab.length;i++)
      { 
       if(tab[i].equals(nom))
    	 {
    		 reponse="Ce nom se trouve dans notre system;";
    		 break;
    	 }
    System.out.print(reponse);
     }
   }
}


...\ Dan /...
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
24 août 2009 à 19:49
j'ai fais comme tu m'a conseillé
maintenant la ligne entier est souligné System.out.print=(reponse);
en mettant souris sur la ligne,il montre message suivant:
System.out.print can not be resolved or is not a field
0
cs_MoH008 Messages postés 238 Date d'inscription lundi 2 mars 2009 Statut Membre Dernière intervention 29 septembre 2011 1
24 août 2009 à 20:18
Salut,
Evident, tu mets ton instruction dans le main:

package Mypackage;

import java.util.Scanner;

public class exercjavascanne
{ 	
   public static void main(String[]args) 

   {

    String[]tab={"Simon","Chris","David","Sarko","Sego","Hardy","Patrick","Franck","Samir"};

    Scanner sc=new Scanner(System.in);
    System.out.print("Entrez un nom:");
    String nom=sc.nextLine();
    String reponse="Ce nom ne se trouve pas dans notre system";

     for(int i=0;i<tab.length;i++)
     { 
      if(tab[i].equals(nom))
    	 {
           reponse="Ce nom se trouve dans notre system;";
    		 break;
    	 }
     }
System.out.print(reponse);
   }
}



==============================================
Possible meet Impossible to become...Possimpible
==============================================
0
cs_MoH008 Messages postés 238 Date d'inscription lundi 2 mars 2009 Statut Membre Dernière intervention 29 septembre 2011 1
24 août 2009 à 20:22
pourquoi une affectation ??
System.out.print=(reponse);


==============================================
Possible meet Impossible to become...Possimpible
==============================================
0
ouabida10 Messages postés 57 Date d'inscription mardi 4 août 2009 Statut Membre Dernière intervention 9 janvier 2011 1
25 août 2009 à 06:35
salut mon ami ... vous avez deux ceci dans votre code :

* dans la bibliothique java on'a pas la méthode nextString
pour réquepéré un string on'a la méthode nextLine

* la 2éme ceci : l'écriture se faite dans le main et pas dans la class
c'est-a-dire il faut que tu mé " System.out.print(reponse);" avant la parentaise de la main

* alors votre programe corrigé est ::

package Mypackage;

import java.util.Scanner;
public class exercjavascanne
{
public static void main(String[]args)
{
String[]tab={"Simon","Chris","David","Sarko","Sego","Hardy","Patrick","Franck","Samir"};
Scanner sc=new Scanner(System.in);
System.out.print("Entrez un nom:");
String nom=sc.nextLine();
String reponse="Ce nom ne se trouve pas dans notre system";
for(int i=0;i<tab.length;i++)
if(tab[i].equals(nom))
{
reponse="Ce nom se trouve dans notre system;";
break;
}
System.out.print(reponse);
}

}




bon courage ...mon ami
0
cs_domxaline Messages postés 327 Date d'inscription jeudi 21 août 2008 Statut Membre Dernière intervention 10 mai 2012 2
25 août 2009 à 09:07
merci beaucoup, ça marche
0
Rejoignez-nous