-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubtractionQuiz (Math.random())
More file actions
31 lines (30 loc) · 1006 Bytes
/
Copy pathSubtractionQuiz (Math.random())
File metadata and controls
31 lines (30 loc) · 1006 Bytes
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
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = 0;
int correct = 0;
int num1 = 0 , num2 = 0;
while (count != 4) {
int n1 = (int) (Math.random() * 10);
int n2 = (int) (Math.random() * 11);
if (n1<n2){
num1 = n2;
num2 = n1;
}
System.out.printf("What is %d - %d = ",num1,num2);
int answer = input.nextInt();
if (num1-num2 == answer) {
System.out.println(num1 + "-" + num2 + "=" + answer + " is " + (num1 - num2 == answer));
correct +=1;
}
else
System.out.println(num1 + "-" + num2 +"="+ answer +" is "+ (num1-num2 == answer));
//counter
count += 1;
}
if (correct>2){
System.out.println("Correct answers: "+correct);
}
}
}