1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 int correctCount = 0; 9 int answer = 0; 10 int number1; 11 int number2; 12 13 long startTime = System.currentTimeMillis(); 14 15 for(int i = 0; i < 10; i++) 16 { 17 number1 = (int)(Math.random() * 15); 18 number2 = (int)(Math.random() * 15); 19 System.out.print(number1 + " + " + number2 + " = ? "); 20 answer = input.nextInt(); 21 if(answer == number1 + number2) 22 correctCount++; 23 } 24 25 input.close(); 26 27 long endTime = System.currentTimeMillis(); 28 long usedTime = (endTime - startTime) / 1000; 29 30 System.out.println("You have " + correctCount + " answers"); 31 System.out.println("Used time: " + usedTime); 32 } 33 }
时间: 2024-10-12 14:40:59