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?
“c++ press any key to continue” Code Answer'scin. get() //(expected for Enter, need #include <iostream>).
In Java this would be System.in.read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With