I want to terminate my program when input is 5
.
My program doesn't close while pressing 5.
Code snippet:
System.out.println("What do you want to do?");
System.out.println("1. Go north");
System.out.println("2. Go east");
System.out.println("3. Go south");
System.out.println("4. Go west");
System.out.println("5. Quit");
System.out.print("Enter command (1-5): ");
// get and return the user's selection
System.exit(0); // exit the menu
return s.nextInt();
How to change it any suggestions?