返回列表 發帖
  1. public class Main2 {

  2.         public static void main(String[] args){
  3.                 TimeThread tt =new TimeThread();
  4.                 tt.start();
  5.                 System.out.println("時間到!");

  6.         }

  7. }
複製代碼
  1. public class TimeThread extends Thread{
  2.         public void run()
  3.         {
  4.                 for(int i=5 ; i>=1 ; i--)
  5.                 {
  6.                         System.out.println(i+"秒");
  7.                         try {
  8.                                 Thread.sleep(1000);
  9.                         } catch (InterruptedException e) {
  10.                                 // TODO 自動產生的 catch 區塊
  11.                                 e.printStackTrace();
  12.                         }
  13.                 }
  14.         }
  15. }
複製代碼

TOP

返回列表