S.O. S.O. - 5 months ago 25
Java Question

Make the console wait for an user input to close

sorry about the seemingly stupid question, but I just can't seem to find the right keywords to find this answer. It's pretty simple: I have a console application that after performing its tasks, must give a 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 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?

x4u x4u
Answer

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