Currently when I input 1, It outputs "Standby mode is enabled" as well as "Standby Mode is disabled" and it loops the output "Standby Mode is disabled" every 5 minutes. How can I only output "Standby mode is enabled" as well as output "Standby Mode is disabled" only once in 5 minutes after I have input 1.
Here are the codes:
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class StandbyMode {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Standby Mode");
System.out.println("Press 1 for Standby mode");
int selectedOption = scanner.nextInt();
if(selectedOption == 1){
System.out.println("Standby mode is enabled");
}else {
System.out.println("Invalid input");
}
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("Standby Mode disabled");
}
}, 0, 300000);
scanner.close();
}
}