- public class Main2 {
- public static void main(String[] args){
- TimeThread tt =new TimeThread();
- tt.start();
- System.out.println("時間到!");
- }
- }
複製代碼- public class TimeThread extends Thread{
- public void run()
- {
- for(int i=5 ; i>=1 ; i--)
- {
- System.out.println(i+"秒");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
- }
- }
複製代碼 |