public class Countdown3 {
private int lin;
private int curSec;
public Countdown3(int lin)throws InterruptedException{
this.lin = lin;
this.curSec = lin;
System.out.println("最后倒计时:" + lin + "秒");
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("倒计时:" + --curSec + "秒");
}
},0,1000);
TimeUnit.SECONDS.sleep(lin);
t.cancel();
System.out.println("Game over!!!");
}

public static void main(String[] args) throws InterruptedException{
new Countdown3(20);
}
}
posted on 2018-05-31 10:35  背起全世界の蜗牛  阅读(1431)  评论(0编辑  收藏  举报