public static void main(String[] args) throws InterruptedException {
CountDown(10);
Count(10);
}
public static void CountDown(int t) throws InterruptedException {
System.out.println("倒计时:"+t);
while(t>0){
Thread.sleep(1000);//线程sleep():休眠,会自动启动,单位:毫秒
t--;
System.out.println("时间是:"+t);
}
System.out.println("时间结束");
}
public static void Count(int limitSec) throws InterruptedException {
System.out.println("Count from "+limitSec);
while(limitSec > 0){
--limitSec;
System.out.println("remians "+ limitSec +" s");
TimeUnit.SECONDS.sleep(1);//休眠1秒
}
System.out.println("Time is out");
}
(1) sleep();休眠,会自动启动