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);
}
}

相关文章:

  • 2021-09-02
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-02-21
  • 2022-02-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案