【发布时间】:2015-03-27 10:14:50
【问题描述】:
我的程序有问题,我希望我的程序的用户编写他想要使用的文件,然后使用循环,根据他输入的单词,将使用一个文件。但是我的程序从来没有进入一个循环,我不知道问题出在哪里。
这是我的代码:
System.out.println("Nom du test case à lancer ? : ");
Scanner saisieUtilisateur = new Scanner(System.in);
//on rentre l'adresse du fichier texte :
String str = saisieUtilisateur.next();
System.out.println(str);
//Integer val = saisieUtilisateur.nextInt();
//System.out.println(val);
String chaine = "";
String File="";
int i=1;
//Choix du fichier a prendre en compte suivant le choix de l'utilisateur
if (str == "hello"){
File = "C:\\exempleANT\\helloWordTexte.txt";
System.out.println("dans la boucle 1");
}
else if(str == "bye"){
System.out.println("dans la boucle 2");
File = "C:\\exempleANT\\FichiersTestExempleHelloWord\\bye.txt";
}
else if(str == "fake"){
System.out.println("dans la boucle 3");
File = "C:\\exempleANT\\FichiersTestExempleHelloWord\\helloWordTexteFake.txt";
}
else {
System.out.println("ErreurTexte!");
System.out.println("dans la boucle 4");
}
这是我运行程序并输入 hello 时控制台中的结果。
hello
hello
ErreurTexte!
dans la boucle 4
【问题讨论】:
-
Butmy programm never enters in one loop。loop在你的程序中在哪里?我确定您的意思是条件语句。 -
提示考虑:您正在使用字符串的参考比较
-
没有任何循环..但是尝试使用上面所说的 .equals() 方法。
标签: java string java.util.scanner