Scanner input = new Scanner(System.in); System.out.print("Is your pet a dog or a cat?: "); String customerInput = input.next(); System.out.print(customerInput); if (customerInput != "dog" && customerInput != "cat"){ System.out.println(); System.out.println("Incorrect input please enter again!\n\n"); System.out.print("Is your pet a dog or a cat?: "); customerInput = input.next(); } else { System.out.print(customerInput); } input.close();
why is dog or cat triggering the first if statement? Makes no sense. I even took out the && and other condition and dog still triggers it. I even printed it out to screen and it's dog. What am I missing here? I'm trying to do a project for school and several lines of my code are being skipped and I can only assume it's the scanner method.
--- Update ---
Wow so apparently the operators are shit in java when it comes to strings because the only one that works is the String method of equals.