-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_1.java
More file actions
41 lines (40 loc) · 1.04 KB
/
game_1.java
File metadata and controls
41 lines (40 loc) · 1.04 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
//This code is for people who want to challenge themselves with basic calculations!
import java.util.*;
import java.security.SecureRandom;
public class game_1{
public static void main(String args[]){
SecureRandom sr= new SecureRandom();
Scanner input = new Scanner(System.in);
int n1=0, n2=0;
int ans=0, score=0, i=1, cnt=0;
String error="";
n1=sr.nextInt(899)+100;
n2=sr.nextInt(100);
while(i<=10){
//i=i+1;
//n1=sr.nextInt(899)+100;
//n2=sr.nextInt(100);
System.out.print("Problem"+i+":"+n1+"-"+n2+"=");
ans = input.nextInt ();
if (ans== n1-n2) {
score=score+ (10-cnt);
System.out.println("Correct!"+"Score: "+score);
n1=sr.nextInt(899)+100;
n2=sr.nextInt(100);
cnt=0;
i=i+1;
}
else{
error=error+"Problem: "+i+" "+n1+"-"+n2+"=\n";
cnt++;
System.out.println("Wrong. Score:"+score);
System.out.println("Answer wrong for "+cnt+" time(s)");
//i=i+1;
}
}//while
int w=10-cnt;
double j=w/10;
System.out.println("Correction rate: "+j);
System.out.println("Wrong answers: "+error);
}//main()
}//class