I'm trying to implement a program that receives user input, if no input within 1 minutes, the program ends, otherwise the timer resets and waits for user input again.
I'm only able to do a timer until now and can't find a way to implement it with user input.
import java.util.Timer;
import java.util.TimerTask;
import java.io.*;
public class test {
public static void main(String[] args){
Timer timer = new Timer();
TimerTask task = new TimerTask() {
int sec = 10;
public void run() {
if (sec > 0){
System.out.println(sec + "seconds");
sec--;
}else {
System.out.println("Time's up");
timer.cancel();
}
}
};
timer.scheduleAtFixedRate( task, 0,1000 );
}
}
Thanks for any help!