返回列表 發帖
  1. import java.util.Date;
  2. public class ch51
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         Scanner s=new Scanner(System.in);
  7.         int a,b,c,d;
  8.         int answer;
  9.         for(int i=0;i<=5;i++)
  10.         {
  11.                 a=(int)(Math.random()*89+11);
  12.                 b=(int)(Math.random()*89+11);
  13.                 c=(int)(Math.random()*89+11);
  14.                 d=(int)(Math.random()*89+11);
  15.                 System.out.print(a+"+"+b+"+"+c+"+"+d+"= ");
  16.                 long t1=new Date().getTime();
  17.                 answer=s.nextInt();
  18.                 long t1=new Date().getTime();
  19.                 long timePassed=t2-t1;
  20.                 if(answer==(a+b+c+d))
  21.                      System.out.print("答對了");
  22.                 else
  23.                      System.out.print("答錯了!答案是"+(a+b+c+d));
  24.                      System.out.println("你剛花了"+timePassed+"毫秒");
  25.                      System.out.println();
  26.         }
  27.     }
  28. }
複製代碼

TOP

返回列表