倒计时模拟

来源:互联网 发布:java系统技术架构图 编辑:程序博客网 时间:2024/06/05 08:06
package com.hnzhrh.Chapter4;import java.util.Scanner;/** *  * @author lawliet * 编写一个模拟倒计时的程序 * 通过线程的休眠来实现 * *///定义一个Thread的派生类public class Countdown extends Thread {public Countdown(int second) throws InterruptedException{for(int i=second;i>=0;i--){System.out.println("Remain : " + i);//线程中断一秒Thread.sleep(1000);}System.out.println("Countdown finished");}public static void main(String[] args) throws InterruptedException {Scanner input = new Scanner(System.in);//用户提示信息System.out.print("Please enter the second : ");int second=input.nextInt();Countdown countdonw = new Countdown(second);input.close();}}

0 0
原创粉丝点击