5.2、线程休眠

2021-12-01  本文已影响0人  金石_832e

sleep

image.png
package com.example.demo.thread;

/**
 * @projectName: demo
 * @package: com.example.demo.thread
 * @className: TestSlepp
 * @author:
 * @description: 模拟倒计时
 * @date: 2021/11/26 17:43
 */
public class TestSleep {
    public static void main(String[] args) throws InterruptedException {
        TestSleep testSleep = new TestSleep();
        testSleep.tenDown();
    }

     void tenDown() throws InterruptedException {
        int num = 10;
        while (num > 0) {
            Thread.sleep(1000);
            System.out.println(num);
            num--;
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读