返回列表 發帖

Date 類別 (二)

本帖最後由 tonyh 於 2013-5-18 16:59 編輯
  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. }
複製代碼

本帖最後由 劉漢文 於 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

  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;
  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/a))
  20.          {
  21.                 System.out.println("且答對了!");
  22.          }else
  23.          {
  24.                 System.out.println("但答錯了!");
  25.          }
  26.     }
  27. }
複製代碼

TOP

  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

  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,h,i,j,k,l,m,n,o;
  10.     a=(int)(Math.random()*9)+1;
  11.     b=(int)(Math.random()*9)+1;
  12.     c=(int)(Math.random()*9)+1;
  13.     d=(int)(Math.random()*9)+1;
  14.     e=(int)(Math.random()*3)+2;
  15.     f=(int)(Math.random()*9)+1;
  16.     g=(int)(Math.random()*9)+1;
  17.     h=(int)(Math.random()*9)+1;
  18.     i=(int)(Math.random()*9)+1;
  19.     j=(int)(Math.random()*9)+1;
  20.     k=(int)(Math.random()*9)+1;
  21.     l=(int)(Math.random()*9)+1;
  22.     m=(int)(Math.random()*9)+1;
  23.     n=(int)(Math.random()*9)+1;
  24.     o=(int)(Math.random()*9)+1;
  25.     System.out.pirntf("(%d+%d-%d+%d*%d)*%d*+%d+%d-%d-%d+(%d*%d)+(%d*%d+%d)= ",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o);
  26.     long t1=new Date().getTime();
  27.     answer=s.nextInt();
  28.     long t2=new Date().getTime();
  29.     System.out.print("你總共花了"+(t2-t1)+"毫秒思考,");
  30.     if(answer==((a+b-c+d*e)*f*+g+h-i-j+(k*l)+(m*n+o)))
  31.     {
  32.       System.out.println("且答對了!");
  33.     }
  34.     else
  35.     {
  36.       System.out.println("且答錯了!");
  37.     }
  38.   }
  39. }
複製代碼

TOP

  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,h,i,j,k,l;
  10.          a=(int)(Math.random()*9+1);
  11.          b=(int)(Math.random()*9+1);
  12.          c=(int)(Math.random()*9+1);
  13.          d=(int)(Math.random()*9+1);
  14.          e=(int)(Math.random()*9+1);
  15.          f=(int)(Math.random()*9+1);
  16.          g=(int)(Math.random()*9+1);
  17.          h=(int)(Math.random()*9+1);
  18.          i=(int)(Math.random()*9+1);
  19.          j=(int)(Math.random()*9+1);
  20.          k=(int)(Math.random()*9+1);
  21.          l=(int)(Math.random()*9+1);
  22.          System.out.printf("(((%d+%d)*%d-%d)+%d)*%d+(%d-%d)*%d*(%d+%d)*%d=",a,b,c,d,e,f,g,h,i,j,k,l);
  23.          long t1=new Date().getTime();
  24.          answer=s.nextInt();
  25.          long t2=new Date().getTime();
  26.          System.out.print("你總共花費了"+(t2-t1)+"毫秒思考,");
  27.          if(answer==((((a+b)*c-d)+e)*f+(g-h)*i*(j+k)*l))
  28.          {
  29.              System.out.print("且答對了!");
  30.          }
  31.          else
  32.          {
  33.              System.out.print("但答錯了!");
  34.          }

  35.      }
複製代碼

TOP

  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,h,i,j,k,l;
  10.         a=(int)(Math.random()*9+1);
  11.         b=(int)(Math.random()*9+1);
  12.         c=(int)(Math.random()*9+1);
  13.         d=(int)(Math.random()*9+1);
  14.         e=(int)(Math.random()*9+1);
  15.         f=(int)(Math.random()*9+1);
  16.         g=(int)(Math.random()*9+1);
  17.         h=(int)(Math.random()*9+1);
  18.         i=(int)(Math.random()*9+1);
  19.         j=(int)(Math.random()*9+1);
  20.         k=(int)(Math.random()*9+1);
  21.         l=(int)(Math.random()*9+1);
  22.         System.out.printf("(%d+%d+%d+%d+%d+%d+%d+%d+%d+%d+%d+%d=",a,b,c,d,e,f,g,h,i,j,k,l);
  23.         long t1=new Date().getTime();
  24.         answer=s.nextInt();
  25.         long t2=new Date().getTime();
  26.         System.out.print("你總共花費了"+(t2-t1)+"毫秒思考,");
  27.         if(answer==a+b+c+d+e+f+g+h+i+j+k+l)
  28.         {
  29.             System.out.println("且答對了!");
  30.         }else
  31.         {
  32.             System.out.println("且答錯了!");
  33.         }
  34.     }
  35. }
複製代碼

TOP

返回列表