代码
package com.erik.thread.stop;
/**
* 模拟倒计时
*
* @author: xiaolh
* @email: [email protected]
* @createTime: 2021/6/6 10:44
*/
public class TestSleepThread01 {
public static void main(String[] args) {
try {
turnDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void turnDown() throws InterruptedException{
int num = 10;
while (true){
Thread.sleep(1000);
System.out.println(num--);
if (num < 0){
break;
}
}
}
}
运行截图