public class Test { public static void main(String[] args){ //程序说明:程序产生10个随机加法,显示正确的个数和测验时间 //产生加法 long startTime = System.currentTimeMillis(); int s1 = 0,s2 = 0,a = 0,t = 0; int i= 0; Scanner input = new Scanner(System.in); while(i < 10){ //产生两个随机数 s1 = (int)(Math.random() * 15 + 1); s2 = ((int)Math.random() * 15 + 1); System.out.print("Whta is " + s1 + "+" + s2 + "? "); a = input.nextInt(); if(s1 + s2 == a) { System.out.println("You are correct!"); t++; } else { System.out.println("You are wrong!"); System.out.println(s1 + " + " + s2 + " should be " + (s1 + s2)); } i++; } //显示正确的个数和时间 System.out.println("correct count is " + t); //显示时间 long endTime = System.currentTimeMillis(); long testTime = endTime - startTime; System.out.println("Test time is " + testTime / 1000 + " seconds"); } }