This site requires JavaScript, please enable it in your browser!
Greenfoot back
Game/maniac
Game/maniac wrote ...

2012/12/19

Scanner string

Game/maniac Game/maniac

2012/12/19

#
The if statement wont work if I type "yes" or "no". What am I doing wrong!? I am using eclipse for this.
public static void End()
{
    Scanner input = new Scanner(System.in);
		
    System.out.println("Do you want to try again? (type 'yes' or 'no')");
		
    String answer = input.next();
		
    if(answer=="yes")
    {
        Loop();
    }else if(answer=="no")
    {
        System.out.println("Good Bye!");
    }
}
Game/maniac Game/maniac

2012/12/19

#
nevermind figured it out I had to do answer.equals("yes")
You need to login to post a reply.