返回列表 發帖
  1. public class Ch100{
  2.         private MyThread th;
  3.         Ch100()
  4.         {
  5.                 th=new MyThread();
  6.                 th.start();
  7.         }
  8.        
  9.         public static void main(String[] args){
  10.                 new Ch100();
  11.         }
  12. }
  13. class MyThread extends Thread
  14. {
  15.         public void run()
  16.         {
  17.                 for(int i=5; i>=1; i--)
  18.                 {
  19.                         System.out.println(i+"秒");
  20.                         try{
  21.                                 sleep(1000);
  22.                         }catch (InterruptedException e){}
  23.                 }
  24.                 System.out.println("時間到!");
  25.                 System.out.println("執行緒名稱:"
  26. +Thread.currentThread().getName());
  27.         }
  28. }
複製代碼

TOP

返回列表