题目内容
下面的程序定义了一个线程TimeThread,该线程每隔1秒钟输出显示一次当前系统时间,在main方法中使用TimeThread类创建3个新线程,并启动这些线程,请将下面的程序填写完整。importjava.util.*;classTimeThreadimplements(1){publicvoidrun(){while(true){DatecurrentTime=newDate();try{(2);//休眠1秒钟}catch(Exceptione){System.out.println(e.toString());}System.out.println(Thread.currentThread().getName()+":"+currentTime);}}}publicclassEx2{publicstaticvoidmain(String[]args){String[]names={"first","second","third"};TimeThreadmyThread=newTimeThread();for(inti=0;i<3;i++){ThreadthreadObj=newThread(myThread,names[i]);(3);//启动线程}}}
查看答案
搜索结果不匹配?点我反馈