public class ThreadPrint extends Thread {
int k = 0;
public ThreadPrint(String name, int k) {
super(name);
this.k = k;
}
public void run() {
int i = k;
System.out.print(getName() + ":");
while (i < 100) {
System.out.println(i + " ");
i += 2;
}
System.out.println(getName() + "end!");
}
public static void main(String[] args) {
ThreadPrint t1 = new ThreadPrint("Thread1", 1);
ThreadPrint t2 = new ThreadPrint("Thread2", 2);
t1.start();
t2.start();
System.out.println("" + t2.activeCount());
}
}
双线程计算100内的奇偶数
最新推荐文章于 2019-08-07 09:40:34 发布