I'm trying to make a basic "20 questions" type of thing to learn how to use if statements with boolean comparators like && in them. However, my "if" statements are not, uh, "doing" (sorry) even though their criteria are being satisfied (as far as I can tell).
When I compile, no matter what "answers" I input, the only output I get is "I'd ask you if I'm right..." ALA:
Think of an object, and I'll try to guess it!
1. Is it an animal, vegetable, or mineral?vegetable
Is it bigger than a breadbox?yes
I'd ask you if I'm right, but I don't really care
I tried googling and searching but I feel like I'm missing out on something so basic that I'm just not seeing it. Here's the code:
Scanner keyboard = new Scanner(System.in);
String response1, response2;
System.out.println("Think of an object, and I'll try to "
+ " guess it!");
System.out.print("1. Is it an animal, vegetable, or mineral?");
response1 = keyboard.next();
System.out.print("Is it bigger than a breadbox?");
response2 = keyboard.next();
if(response1 == "animal" && response2 == "yes")
{
System.out.println("You're thinking of a moose");
}
if(response1 == "animal" && response2 == "no")
{
System.out.println("You're thinking of a squirrel");
}
if(response1 == "vegetable" && response2 == "yes")
{
System.out.println("You're thinking of a watermelon");
}
if(response1 == "vegetable" && response2 == "no")
{
System.out.println("You're thinking of a carrot");
}
if(response1 == "mineral" && response2 == "yes")
{
System.out.println("You're thinking of a Camaro");
}
if(response1 == "mineral" && response2 == "no")
{
System.out.println("You're thinking of a paper clip");
}
System.out.println("I'd ask you if I'm right, but I don't really care");
Thanks in advance to any respondents!