模拟倒数10个数,打印 “新年快乐”
package Thread;
public class ThreadTest1 extends Thread {
private boolean flag = true;
public void run() {
System.out.println("倒计时开始!!");
for(int i=10;i>0;i--) {
System.out.println(i);
if(i==6) return;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("新年快乐!!");
}
public static void main(String[] args) {
ThreadTest1 tt = new ThreadTest1();
tt.start();
System.out.println("主线程开始等待");
try {
tt.join(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("可惜不是你,陪我到最后");
}
}