0

I am trying to make this program work. It checks if a string of text entered by the user is equal to one of three. Here is my code:

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;
}

The problem is, it automatically goes to "null".

  • Please correct the subject of question : if..else if..else is not a loop. A loop is something which keeps on going till its condition is true e.g. while, for, do..while, whereas an if block is executed just once when a condition is true. – Kajal Sinha Jun 25 '14 at 16:31
  • I am a newbie to programming. Thanks. Can you answer the question? How do you change the title? – user3776081 Jun 25 '14 at 16:53
  • if(choice.equals(choice1)){...} use .equals instead of == as mentioned by jhobbie – Kajal Sinha Jun 25 '14 at 17:05

1 Answers1

2

For string equality you have to use string1.equals(string2).

jhobbie
  • 1,016
  • 9
  • 18