Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make the console wait for a user input to close

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.

The thing is, if I just "let it run", the output message will be printed but the console will close shortly afterwards, leaving no time to read the message.

As far as I remember, in C++, every console application will end with a "press any key to exit" or something like that. In C# I can simulate this behavior with a

Console.ReadKey(); 

But how can I do it in Java? I'm using the Scanner class, but given that "input" is my instance of Scanner:

input.next() System.exit(0); 

"Any key" will work, except for return, which is quite a big deal here. Any pointers?

like image 659
makoshichi Avatar asked May 17 '11 14:05

makoshichi


People also ask

How do you do press any key to continue C++?

“c++ press any key to continue” Code Answer'scin. get() //(expected for Enter, need #include <iostream>).


1 Answers

In Java this would be System.in.read()

like image 89
x4u Avatar answered Oct 24 '22 15:10

x4u