问题 问答题

阅读下列程序,请写出该程序的功能。

import java util.*;

class MyThread extends Thread {

int pauseTime; String name;

public MyThread (int x, String n) { pauseTime = x; name = n; }

public void run() {

for(int i = 1;i <= 4; i++) {

try {

System.out.println(name +":" +new Date(System.currentTimeMillis()));

Thread.sleep(pauseTime);

}catch(Exception e){ }

}

}

}

public class Test36{

static public void main(String[] args) {

MyThread thread1 = new MyThread (1000,"Fast Thread"); thread 1 .start();

MyThread thread2 = new MyThread (3000,"Slow Thread"); thread2.start();

}

}

 

答案

参考答案:

在程序中创建两个线程,该两个线程交替执行,按两个不同的时间间隔显示当前时间。

单项选择题
填空题