我正在努力让这个程序发挥作用。它检查用户输入的文本字符串是否等于三个之一。这是我的代码:
boolean acceptableanswer;
if(choice == choice1){
acceptableanswer=true;
return choice1;
}else if(choice == choice2){
acceptableanswer=true;
return choice2;
}else if(choice == choice3){
acceptableanswer=true;
return choice3;
}else{
acceptableanswer=false;
return null;
}
问题是,它自动变为“null”。
最佳答案
对于字符串相等,您必须使用string1.equals(string2)
。
关于Java If-Else 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24414024/