其他分享
首页 > 其他分享> > 十四、线程休眠

十四、线程休眠

作者:互联网

倒计时Demo:

public class ThreadSleep2 {

    public static void main(String[] args) {
        int i =10;
        try {
            cutDown(i);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    //倒计时
    public static void cutDown(int i) throws InterruptedException {
        while (true){
            Thread.sleep(1000);
            if (i>=0){
                System.out.println(i--);
            }else break;
        }
    }
    
}

 

标签:int,InterruptedException,倒计时,休眠,线程,sleep,十四,public
来源: https://www.cnblogs.com/epiphany8/p/16271451.html