JAVA线程——利用sleep制作了个倒计时(二)

package Thread;

public class SimpleTimer {
    private static int count;
    public static void main(String[] args) {
        count = 60;
        int remaining;
        while(true){
            remaining = countDown();
            if(remaining == 0){
                break;
            }
            else{
                System.out.println("Remaining " + count + " second(s)");
            }
            try {
                Thread.sleep(1000);
            }catch (Exception e){
                System.out.println(e.getMessage());

            }
        }
        System.out.println("Done");
    }

    private static int countDown() {
        return count--;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_40632760/article/details/86327486