import java.util.Calendar;
public class Clock {
public static void main(String[] args) {
Thread clockThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
System.out.printf("\r%02d:%02d:%02d", hour, minute, second);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
clockThread.start();
}
}
java多线程时钟,在eclipse运行效果不好
最新推荐文章于 2025-05-28 23:39:14 发布