0

what is the problem with the while loop that i've set up?

    String animal;
    animal = user_input.next();
    animal = animal.toLowerCase();

    while ((animal != "c") && (animal != "d")) {
        System.out.println("Invalid input, please enter c for a cat or d for a dog");
        animal = user_input.next();
        animal = animal.toLowerCase();
    }
    if (animal == "c") {
        System.out.println("you have a cat");
    } else {
        System.out.println("you have a dog");
    }
Lucy
  • 1

0 Answers0