编写MyThread类继承自Thread
。创建MyThread类对象时可指定循环次数n。
功能:输出从0到n-1的整数。 并在最后使用System.out.println(Thread.currentThread().getName()+" "+isAlive())
打印标识信息
裁判测试程序:
import java.util.Scanner; /*这里放置你的答案,即MyThread类的代码*/ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Thread t1 = new MyThread(Integer.parseInt(sc.next())); t1.start(); } }
输入样例:
3
输出样例:
0
1
2
标识信息
代码展示
class MyThread extends Thread{
private int count;
MyThread(int count){
this.count=count;
}
public void run(){
for (int i = 0; i < count; i++) {
System.out.println(i);
}
System.out.println(Thread.currentThread().getName()+" "+isAlive());
}
}