- import java.util.Date;
- import java.util.Scanner;
- public class ch66
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int answer;
- int a,b,c,d,e,f,g,h,i,j,k,l;
- a=(int)(Math.random()*9+1);
- b=(int)(Math.random()*9+1);
- c=(int)(Math.random()*9+1);
- d=(int)(Math.random()*9+1);
- e=(int)(Math.random()*9+1);
- f=(int)(Math.random()*9+1);
- g=(int)(Math.random()*9+1);
- h=(int)(Math.random()*9+1);
- i=(int)(Math.random()*9+1);
- j=(int)(Math.random()*9+1);
- k=(int)(Math.random()*9+1);
- l=(int)(Math.random()*9+1);
- 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);
- long t1=new Date().getTime();
- answer=s.nextInt();
- long t2=new Date().getTime();
- System.out.print("你總共花費了"+(t2-t1)+"毫秒思考,");
- if(answer==a+b+c+d+e+f+g+h+i+j+k+l)
- {
- System.out.println("且答對了!");
- }else
- {
- System.out.println("且答錯了!");
- }
- }
- }
複製代碼 |