第16周作业
题目1:编写一个应用程序,利用Java多线程机制,实现时间的同步输出显示。
代码:
public class Text {
public static void main(String[] args) {
ThreadTime t=new ThreadTime();
t.start();
}
}
import java.util.Date;
public class ThreadTime extends Thread {
public void run(){
Date date;
while(true){
date=new Date();
System.out.println(date);
try {
this.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
运行结果

浙公网安备 33010602011771号