package nameyu; import java.util.Scanner; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub final int NUMBER_OF_ADDITION =10;//产生10道题 int corretcount=0; int count=0; String output=""; long startTime=System.currentTimeMillis(); Scanner input=new Scanner(System.in); while(count<NUMBER_OF_ADDITION){ int number1=(int)(Math.random()*16+1); int number2=(int)(Math.random()*16+1); System.out.print("what is "+number1+"+"+number2+"?"); int answer=input.nextInt(); if(number1+number2==answer){ System.out.println("you are correct!"); corretcount++; }else System.out.println("you answer is wrong.\n"+number1+"+"+number2+"should be"+(number1+number2)); count++; output+="\n"+number1+"+"+number2+"="+answer+((number1+number2==answer)?"correct":"wrong"); } long endTime=System.currentTimeMillis(); long testTime=endTime-startTime; System.out.println("Correct count is"+corretcount+"\nTest time is "+testTime/1000+" seconds\n"+output); } }
|