How to stop a running TimerTask
问题 I am trying to make a simple timer that plays a beep after the specified number of seconds. I managed to get it to work, but the TimerTask continues to run after the beep. Now do I stop execution? Here is my code: import java.util.Scanner; import java.util.Timer; import java.util.TimerTask; import java.awt.Toolkit; class Alarm { public static void main(String[] args) { long delay; Scanner scan = new Scanner(System.in); System.out.print("Enter a delay in seconds: "); delay = scan.nextInt()