Java If-Else循环

Java If-Else循环,java,if-statement,Java,If Statement,我正在努力使这个计划发挥作用。它检查用户输入的文本字符串是否等于三个字符串之一。这是我的密码: boolean acceptableanswer; if(choice == choice1){ acceptableanswer=true; return choice1; }else if(choice == choice2){ acceptableanswer=true; return choice2; }else if(choice == choice3){

我正在努力使这个计划发挥作用。它检查用户输入的文本字符串是否等于三个字符串之一。这是我的密码:

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)
请更正问题主题:if..else if..else不是循环。循环是持续进行直到其条件为真的东西,例如while,for,do..while,而if块在条件为真时只执行一次。我是编程新手。谢谢你能回答这个问题吗?如何更改标题?如果(choice.equals(choice1)){…}使用.equals代替jhobbie提到的==谢谢!这使它起了作用。