java loop to repeat program

前端 未结 3 379
余生分开走
余生分开走 2021-01-28 07:17

I am extremely new to java I am in my second week in classes or so--

I need my program to keep going or exit according to the user. It is a payroll calculation and I wan

3条回答
  •  情深已故
    2021-01-28 07:25

    Here is a brief idea of how to do this:

    String choice = "y";
    
    while(true) {
        //Take input
        System.out.print("Do you want to continue (y/n)?");
        choice = reader.nextLine();
    
        if(choice.equalsIgnoreCase("n")) break;
        //else do your work.
    }
    

    You can also sue do-while to get what you want. You may need to make some changes but then that is the entire idea. It is just a hint.

提交回复
热议问题