Make the console wait for a user input to close

后端 未结 8 1000
遥遥无期
遥遥无期 2020-11-30 01:49

I have a console application that after performing its tasks, must give feedback to the user, such as \"operation completed\" or \"operation failed\" and the detailed error.

8条回答
  •  感动是毒
    2020-11-30 01:59

    You can just use nextLine(); as pause

    import java.util.Scanner
    //
    //
    Scanner scan = new Scanner(System.in);
    
    void Read()
    {
         System.out.print("Press any key to continue . . . ");
         scan.nextLine();
    }
    

    However any button you press except Enter means you will have to press Enter after that but I found it better than scan.next();

提交回复
热议问题