0

I'm I total beginner and can't figure out what the problem is here - I want the scanner input to close after when the user enters "exit". When I try my code it says "Exit >" and I'm still able to do input. Is it something with the scope of input.close()?

    String command;     
    do {
        System.out.print("> ");
        command = input.nextLine();


        switch (command) {
        case "register new dog":
            System.out.println("You gave command: register new dog");
            System.out.println("Command? ");
            break;

        case "increase age":
            System.out.println("You gave command: increase age");
            System.out.println("Command? ");
            break;

        case "list dogs":
            System.out.println("You gave command: list dogs");
            System.out.println("Command? ");
            break;

        case "remove dogs":
            System.out.println("You gave command: remove dogs");
            System.out.println("Command? ");
            break;

        case "exit":
            System.out.println("Goodbye!");
            break;

        default:
            System.out.println("Error: invalid command, choose again: ");
            System.out.println("Register new dog");
            System.out.println("Increase age");
            System.out.println("List dogs");
            System.out.println("Remove dogs");
            System.out.println("Exit");



        }

    } while (command != "exit");

    input.close(); 
deieli
  • 1

0 Answers0