HW4.2

 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

HW4.2的相关文章

Stats 102A HW4

Stats 102A HW4 Due March 3, 2020General Notes• You will submit a minimum of three files, the core files must conform to the followingnaming conventions (including capitalization and underscores). 123456789 is a placeholder,please replace these nine d

HW4.30

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 9 System.out.print("Enter the balance amount: "); 10 double balance = input.nextDouble(); 11 Syste

HW4.28

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 9 System.out.print("Enter the year: "); 10 int year = input.nextInt(); 11 System.out.print("E

HW4.1

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 9 System.out.print("Enter an int value, the program exits if the input is 0: "); 10 int inputValue

HW4.3

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 final double POUND_PER_KILOGRAM = 2.2; 6 7 System.out.println("KILOGRAM" + "\t" + "POUND"); 8 for(int i = 1; i < 200; i += 2) 9 System.out.println(

HW4.32

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 System.out.print("Enter your lottery pick (two digits): "); 9 int guess = input.nextInt(); 10 11 i

HW4.31

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 9 System.out.print("Enter the balance: "); 10 double balance = input.nextDouble(); 11 System.out.p

HW4.19

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 for(int i = 1; i <= 8; i++) 6 { 7 for(int j = 8 - i; j > 0; j--) 8 System.out.print(" "); 9 for(int j = 1; j <= i; j++) 10 System.out.print((int)(Math.pow(2, j -

HW4.6

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 final double MILES_PER_KILOGRAM = 1.609; 6 7 System.out.println("Miles" + "\t" + "Kilograms" + "\t" + "Kilograms" + "\t"