-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGame.java
More file actions
61 lines (42 loc) · 1.77 KB
/
NumberGame.java
File metadata and controls
61 lines (42 loc) · 1.77 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
59
60
61
import java.util.Scanner;
import java.util.Random;
public class NumberGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random rdn = new Random();
boolean flag = true;
int totalWon = 0;
int totalAttempt = 0;
while (flag) {
int generateNum = rdn.nextInt(100);
System.out.println("Random number is generated ");
System.out.println("-------------------------------------");
int attempt = 0;
System.out.println("You can Enter the number between 1 - 100");
System.out.println("You have a 3 limited attempt");
while (attempt < 3) {
attempt++;
System.out.println();
System.out.println(attempt + ". Guess the number for the generated number");
int guessNum = sc.nextInt();
totalAttempt++;
if (generateNum == guessNum) {
System.out.println("Congratulations ! Your guess number is correct");
totalWon++;
break;
}
else if (generateNum > guessNum) {
System.out.println(" generated Number is too high");
}
else {
System.out.println(" generated Number is too low");
}
}
System.out.println("you wont to play game again than enter true otherwise enter false ");
flag = sc.nextBoolean();
}
System.out.println("-------- Score Board -----------");
System.out.println("Number of Total Attempt is : " + totalAttempt);
System.out.println("Number of total round won by you is : " + totalWon);
}
}