Continue a while loop after exception

前端 未结 6 543
春和景丽
春和景丽 2021-01-16 12:39

i have this piece of code. I wanted to return to the beginning of loop and ask for user input again. However, it always loops without stopping to ask for input. What is wron

6条回答
  •  我在风中等你
    2021-01-16 13:20

    Try doing do while loop.

           do
            {
                try
                {
    
                   //get user input
                    done = true; 
                } 
    
                catch (InputMismatchException e)
                {
                    System.out.println("The number entered needs to be a int");
                }
    
    
            } while (!done);
    

提交回复
热议问题