I want to know what is wrong with this :
if (q == "outside" && q1 == "not alive") {
System.out.println("bison");
}
This statement works perfectly:
if (q == "outside" && q1 == "alive") {
System.out.println("bison");
}
All of the if statements containing "alive" works perfectly, but all of the if statements containing "not alive" does not work.
This is an exercise which I have to do without using else if or else.
full code :-
import java.util.Scanner;
class age04 {
public static void main(String [] args) {
Scanner keyboard = new Scanner(System.in);
String q, q1,;
System.out.println("Two more questions, baby!");
System.out.println("Think of something and i'll try to guess it!");
System.out.println("Question 1) Does it stay inside or outside or both");
q = keyboard.next();
System.out.println("Question 1) Is it alive?");
q1 = keyboard.next();
if (q == "inside" && q1 == "alive") {
System.out.println("houseplant");
}
if (q == "inside" && q1 == "not alive") {
System.out.println("shower curtain");
}
if (q == "outside" && q1 == "alive") {
System.out.println("bison");
}
if (q == "outside" && q1 == "not alive") {
System.out.println("bison");
}
if (q == "both" && q1 == "alive") {
System.out.println("dog");
}
if (q == "both" && q1 == "not alive") {
System.out.println("cell phone");
}
}
}