第16周作业

题目1:编写一个应用程序,利用Java多线程机制,实现时间的同步输出显示。

import java.util.Date;

public class Timet extends Thread {
    public void run() {//重写run方法
        Date date;
        while(true){
            date = new Date();
            System.out.println(date);//获取的当前时间
            try {
                sleep(1000);//休眠1s
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        Timet time = new Timet();
        time.start();
    }
}

运行界面

原文地址:https://www.cnblogs.com/mai98/p/12075123.html