第十六周作业
题目1:编写一个应用程序,利用Java多线程机制,实现时间的同步输出显示。
package factorial; import java.util.Date; public class DateTime implements Runnable { public void run() { Date time; while(true) { time = new Date(); System.out.println(time); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
package factorial; public class Time1 { public static void main(String[] args) { Thread test = new Thread(new DateTime());//目标对象 test.start(); } }
运算结果: