- import java.util.Scanner;
- import java.util.Date;
- public class ch51
- {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- int a, b, c, d;
- int answer;
- for(int i=0; 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 t1=new Date().getTime();
- long 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.println();
- }
- }
複製代碼 |