注意:简单来说就是利用了sleep睡眠的方法进行了倒计时
package com.yyf.ThreadSleep;
// 模拟倒计时
public class TestSleep2 implements Runnable{
public static void main(String[] args) {
TestSleep2 s = new TestSleep2 ();
new Thread(s).start ();
}
@Override
public void run() {
int num=10;
while (true){
if (num<=0){
break;
}
try {
Thread.sleep (1000);
} catch (InterruptedException e) {
e.printStackTrace ();
}
System.out.println (num--);
}
}
}
10
9
8
7
6
5
4
3
2
1