System.out.print("游戏马上开始,请准备,按Enter键开始:");
Scanner sc = new Scanner(System.in);
sc.nextLine();
System.out.println("游戏开始!!!");
//游戏开始
Calendar cal = Calendar.getInstance();
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + 20);//二十秒的时间
Date end = cal.getTime();
long endlong = end.getTime();
int count = 1;
while (endlong - new Date().getTime() >= 0) {
sc.nextLine();
System.out.print("你按了第" + count + "次Enter键");
count++;
}
System.out.println();
System.out.println("游戏结束!! !");
System.out.println("你一共在20秒内按了" + count + "次Enter");
double Pin = count / 20.0;
DecimalFormat dec = new DecimalFormat(".##");
System.out.println("您的频率是" + dec.format(Pin) + "秒/次");
}