package com.haohao.test;
/**
* @author zhh
* @description 模拟倒计时
* @date 2020/9/16
*/
public class TestSleep {
public static void down() throws InterruptedException {
int num = 10;
while (true) {
Thread.sleep(1000);// 线程一秒钟休眠一次
System.out.println(num--);
if (num <= 0) {
break;
}
}
}
public static void main(String[] args) {
try {
down();// 模拟倒计时
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
输出结果:
10
9
8
7
6
5
4
3
2
1