返回列表 發帖
本帖最後由 劉漢文 於 2013-5-18 17:13 編輯
  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, e, f, g;
  10.          a=(int)(Math.random()*900)+10;
  11.          b=(int)(Math.random()*900)+10;
  12.          c=(int)(Math.random()*900)+10;
  13.          d=(int)(Math.random()*900)+10;
  14.          e=(int)(Math.random()*900)+10;
  15.          f=(int)(Math.random()*900)+10;
  16.          g=(int)(Math.random()*900)+10;
  17.          System.out.printf("%d-%d-%d+%d-%d-%d+%d= ",a,b,c,d,e,f,g);
  18.          long t1=new Date().getTime();
  19.          answer=s.nextInt();
  20.          long t2=new Date().getTime();
  21.          System.out.print("你總共花了"+(t2-t1)+"毫秒思考, ");
  22.          if(answer==(a-b-c+d-e-f+g))
  23.          {
  24.                 System.out.println("且答對了!");
  25.          }else
  26.          {
  27.                 System.out.println("但答錯了!");
  28.          }
  29.     }
  30. }
複製代碼

TOP

返回列表