File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ fixes #363
2+ import java.util.Timer;
3+ import java.util.TimerTask;
4+ import java.text.SimpleDateFormat;
5+ import java.util.Date;
6+
7+ public class AlarmClock {
8+
9+ public static void main(String[] args) {
10+ // Set the alarm time (24-hour format)
11+ String alarmTime = "15:30"; // Change this to your desired alarm time
12+
13+ // Create a timer
14+ Timer timer = new Timer();
15+
16+ // Define a task to be executed when the alarm time is reached
17+ TimerTask task = new TimerTask() {
18+ public void run() {
19+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
20+ String currentTime = sdf.format(new Date());
21+ if (currentTime.equals(alarmTime)) {
22+ System.out.println("Alarm! It's time to wake up!");
23+ // You can replace the message with any action you want
24+ }
25+ }
26+ };
You can’t perform that action at this time.
0 commit comments