为什么像condition
这样的布尔条件总是返回true?即使变量reponse
等于常量OUI
或NON
;这个Java程序为什么有无限循环?
final String OUI = "O";
final String NON = "N";
String reponse = OUI;
// some code was omitted
do {
// some code was omitted
// true
boolean condition = false;
do {
System.out.println(MSG_SOL_TRONCON);
reponse = mScanner.nextLine();
// Debug
System.out.println("Reponse:" + reponse + ":fin");
/*
// Boucle infinie, problème avec la condition
// Infinite Loop
condition = !((reponse == NON) || (reponse == OUI));
System.out.println("Condition : " + condition);
if (condition) {
System.out.println(MSG_ERR_TRONCON);
} // if
*/
} while(condition);
} while (reponse != NON);
尝试'NON.equals(响应)'不'我们=='或'='用绳子See.http:!/ /stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – bradimus