-2
package test;
import java.util.Scanner;
public class Test {
public static Scanner input = new Scanner (System.in);
public static void main (String [] args) {
System.out.println("Whats your favorite pet? Dog Cat or Bird");
String y = input.next();
String b = y.toUpperCase();
if(b == "DOG") {
System.out.println("Dog go woof woof");
}
if(b == "CAT") {
System.out.println("Cat go meow meow");
}
if (b == "BIRD") {
System.out.println("Bird go churp churp");
}
else System.out.println("no pets");
}
}

THIS IS THE ANSWER I GOT. Whats your favorite pet? Dog Cat or Bird i typed in "dog" but it printed out
"no pets".

Marco Bonelli
  • 55,971
  • 20
  • 106
  • 115
  • Also, once you fix using `.equals` (or `.equalsIgnoreCase`) you will want to add the missing `else`(s) between the `CAT` and `BIRD` test cases. Without those, the final `else` only applies to the `BIRD` `if`. – Elliott Frisch May 29 '22 at 03:19
  • Next time please format your code properly. This is just an illegible mess. – user207421 Jun 01 '22 at 00:34

0 Answers0