package 倒计时;
import java.util.Scanner;
class MyThread implements Runnable{
Scanner s=new Scanner(System.in);
//gprivate int time=6;
@Override
public void run() {
int time=6;
// TODO Auto-generated method stub
System.out.println("倒计时"+(time-1)+"秒");//打印倒计时5秒
try {
for (int i = 1; i <= 5; i++) {//遍历输出
Thread.sleep(1000, 100);
time--;//实现从5,4,3,2,1,
if(time!=0){//不输出0这个时间
System.out.println(time);
}
}
System.out.println("开始");
System.out.println("请选择:");
System.out.println("1.重新刷新");
System.out.println("2.查看");
System.out.println("3.推出");
int key=s.nextInt();
switch (key) {
case 1:
System.out.println("重新刷新");
run();
break;
case 2:
System.out.println("查看");
break;
case 3:
System.out.println("推出");
System.exit(0);
default:
System.out.println("输入有误,推出系统");
System.exit(0);
break;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("系统出现异常");
}
System.out.println();
}
}
public class countdown {
public static void main(String[] args) {
MyThread my=new MyThread();//初始化对象
Thread t=new Thread(my,"线程");
t.start();//线程开始
}
}