forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubtractionQuizLoop.java
More file actions
executable file
·58 lines (56 loc) · 1.97 KB
/
SubtractionQuizLoop.java
File metadata and controls
executable file
·58 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* */ package ch05;
/* */
/* */ import java.util.Scanner;
/* */
/* */ public class SubtractionQuizLoop {
/* */ public static void main(String[] args) {
/* 7 */ int NUMBER_OF_QUESTIONS = 5;
/* 8 */ int correctCount = 0;
/* 9 */ int count = 0;
/* 10 */ long startTime = System.currentTimeMillis();
/* 11 */ String output = "";
/* 12 */ Scanner input = new Scanner(System.in);
/* */
/* 14 */ while (count < 5) {
/* */
/* 16 */ int number1 = (int)(Math.random() * 10.0D);
/* 17 */ int number2 = (int)(Math.random() * 10.0D);
/* */
/* */
/* 20 */ if (number1 < number2) {
/* 21 */ int temp = number1;
/* 22 */ number1 = number2;
/* 23 */ number2 = temp;
/* */ }
/* */
/* */
/* 27 */ System.out.print("What is " + number1 + " - " + number2 + "? ");
/* */
/* 29 */ int answer = input.nextInt();
/* */
/* */
/* 32 */ if (number1 - number2 == answer) {
/* 33 */ System.out.println("You are correct!");
/* 34 */ correctCount++;
/* */ } else {
/* */
/* 37 */ System.out.println("Your answer is wrong.\n" + number1 + " - " + number2 + " should be " + (number1 - number2));
/* */ }
/* */
/* */
/* 41 */ count++;
/* */
/* 43 */ output = output + "\n" + number1 + "-" + number2 + "=" + answer + ((number1 - number2 == answer) ? " correct" : " wrong");
/* */ }
/* */
/* */
/* 47 */ long endTime = System.currentTimeMillis();
/* 48 */ long testTime = endTime - startTime;
/* */
/* 50 */ System.out.println("Correct count is " + correctCount + "\nTest time is " + (testTime / 1000L) + " seconds\n" + output);
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch05/SubtractionQuizLoop.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/