I have a Java program that automates a long list of tasks and it pauses for 15 seconds after each completed task then restarts. Is there a way to end this program by entering any keystrokes from the user? I don't want to have to ask the user if they want to end the program and have to stop and ask every so often as the user is not going to be around to respond. I know you can press "Control + C" to stop the program while in the command prompt but is there a more elegant way than this?
The program is something like this:
while(true) {
// automatic task code
}
Thank You
**Edit* My question is more of a "Can I make a program when I input an unsolicited input that can abruptly end the program?"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…