首页 > 其他 > 详细

实现倒计时

时间:2018-08-24 21:44:45      阅读:162      评论:0      收藏:0      [点我收藏+]
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();休眠,会自动启动

实现倒计时

原文:https://www.cnblogs.com/sunda847882651/p/9532056.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!