-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumbergame.java
More file actions
41 lines (36 loc) · 1.71 KB
/
numbergame.java
File metadata and controls
41 lines (36 loc) · 1.71 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
import java.util.Scanner;
import java.util.Random;
public class numbergame {
public static void main(String[]Args) {
Scanner sc = new Scanner(System.in);
Random ra = new Random();
int score = 0;
System.out.println ("Enter number of rounds");
int rounds = sc.nextInt();
System.out.println("Enter number of attempts");
int attempts = sc.nextInt();
for (int i = 1; i <= rounds; i++) {
System.out.println(" We will generate the random number for round " + i + " by the help of the system");
int randomnumber = ra.nextInt(100) + 1;
for (int j = 1; j <= attempts; j++) {
System.out.println("Guess number is:");
int guessednumber = sc.nextInt();
if (guessednumber == randomnumber) {
System.out.println("congratulation!,you have guessed the number correct");
score += 50;
break;
} else if (guessednumber > randomnumber) {
System.out.println("oops!,you have guessed too high");
score -= 20;
} else {
System.out.println("oops!,you have guessed too low");
score -= 20;
}
}
System.out.println("Random number is: " +randomnumber);
System.out.println("Round " + i +" score is: "+ score);
System.out.println("Round " + i + " is finished");
score = 0;
}
}
}