Java Check Input and Exit function?

Joe Cat

New member
For my Java program, I have been trying to write a code that checks user input. When user enters String, 'error' message would be come out and it accepts only Integer. It is implemented with switch case to choice for User. Switch case also includes Exit function if Users want to exit, type integer 5 to Exit from program. Could anyone help me to fix my code? Thanks.



public static void main (String args[]) throws Exception

{
int choice =0;
while (choice !=5)
{
System.out.println ("5 to exit");
System.out.println ("enter choice");
Scanner scan = new Scanner (System.in);
choice = scan.nextInt();



switch (choice)
{
case '5' : exit();
}
 
Back
Top