【六袆 - Java】多线程打印倒计时Demo;多线程休眠;

代码

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;
            }
        }
    }
}

运行截图

 

猜你喜欢

转载自blog.csdn.net/qq_41086359/article/details/117653101
今日推荐