返回列表 發帖
  1. package tw.kuas.edu.tw;

  2. public class Main {

  3.         public static void main(String[] args) throws InterruptedException {
  4.                 // TODO 自動產生的方法 Stub
  5.                 System.out.println("Thread start.");
  6.                 Prog thread = new Prog();
  7.         thread.start();
  8.         System.out.println("Thread end.");
  9.         }

  10. }
複製代碼
  1. package tw.kuas.edu.tw;

  2. public class Prog extends Thread
  3. {
  4.         public void run()
  5.         {
  6.                 for(int i=100; i>=0; i--)
  7.             {
  8.                     try {
  9.                                                 Thread.sleep(1000);
  10.                                                 System.out.println(i+"s!");
  11.                                         } catch (InterruptedException e) {
  12.                                                 // TODO 自動產生的 catch 區塊
  13.                                                 e.printStackTrace();
  14.                                         }
  15.                     
  16.             }        
  17.             System.out.println("Time's up!");
  18.         }
  19. }
複製代碼

TOP

返回列表