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

TOP

返回列表