返回列表 發帖
  1. import java.util.Date;
  2. import java.util.Scanner;
  3. public class ch66
  4. {
  5.     public static void main(String args[])
  6.     {
  7.          Scanner s=new Scanner(System.in);
  8.          int answer;
  9.          int a, b, c, d;
  10.          a=(int)(Math.random()*90)+10;    //產生介於10~99之隨機亂數
  11.          b=(int)(Math.random()*90)+10;
  12.          c=(int)(Math.random()*90)+10;
  13.          d=(int)(Math.random()*90)+10;
  14.          System.out.printf("%d+%d+%d+%d= ",a,b,c,d);
  15.          long t1=new Date().getTime();
  16.          answer=s.nextInt();
  17.          long t2=new Date().getTime();
  18.          System.out.print("你總共花費了"+(t2-t1)+"毫秒思考, ");
  19.          if(answer==(a+b+c+d))
  20.          {
  21.                 System.out.println("且答對了!");
  22.          }else
  23.          {
  24.                 System.out.println("但答錯了!");
  25.          }
  26.     }
  27. }
複製代碼

TOP

返回列表