- import java.util.Scanner;
- import java.util.Date;
- public class ch52
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int a, b, c, d;
- int answer;
- for(int i=1; i<=5; i++)
- {
- a=(int)(Math.random()*89+11);
- b=(int)(Math.random()*89+11);
- c=(int)(Math.random()*89+11);
- d=(int)(Math.random()*89+11);
- System.out.print(a+"+"+b+"+"+c+"+"+d+"= ");
- long t1=new Date().getTime();
- answer=s.nextInt();
- long t2=new Date().getTime();
- answer=timepassed=t2-t1;
- if(answer==(a+b+c+d))
- System.out.print("答對了!!!")
- else
- System.out.print("答錯了!!! 正確答案時"+(a+b+c+d)+". ")
- System.out.println("你剛花了"+timepassed+"毫秒思考")
- System.out.print();
- }
- }
- }
複製代碼 |