1.【请复制本程序,作为java程序代码,进行编译,补充填写缺失代码部分,并实现题目要求功能,从而获得空白填写所需的内容。】
编写无限计时程序,从0:1开始计时,一直循环计时,计时到60秒,变为1:0,以此类推。###
0:1
0:2
0:3
0:4
0:5
0:6
0:7
。。。
0:58
0:59
1:0
1:1
1:2
1:3
1:4
。。。
package naizi;
class TM extends Thread {
static int m=0; //计“分”的变量
public void run() { //线程体
while(true){
try{
sleep(100000); //无限等待
}
catch(InterruptedException e){
m++;
}
}
}
}
public class TS extends TM {
static int s=0; //计“秒”的变量
Thread tm;
public TS(Thread t) {
tm=t;
}
public void run() { //线程体
while(true){
try{
if(s==59){ //秒到59时
s=0;
TM.m++;
}
else{
s++;
}
sleep(1000);
System.out.println(TM.m+":"+TS.s);
}
catch(InterruptedException e){}
}
}
public static void main(String agr[]){
TM t1=new TM();
t1.start();
TS t2=new TS(t1);
t2.start();
}
}