第16周作业

题目1:

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

代码:

//Time类继承Thread
//重写run方法
//启动线程
package wyr;
import java.util.Date;
class Time extends Thread {
    public void run() {
        while (true) {
            Date date = new Date();
            System.out.println(date);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class TimeShow {
    public static void main(String[] args) {
        Time time = new Time();
        time.start();
    }
}

运行结果:

原文地址:https://www.cnblogs.com/leeyangtongxue/p/12069341.html