-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_1.java
58 lines (49 loc) · 1.32 KB
/
task_1.java
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
import java.lang.Math;
import java.util.Scanner;
public class task_1{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int min = 1;
int max = 100;
int i = 0;
int limit = 10;
int wins = 0;
System.out.println("Enter the no of rounds.... : ");
int round = sc.nextInt();
while (i < round) {
System.out.println("Round : " + (i + 1));
int random_num = (int)(Math.random() * (max - min + 1) + min);
System.out.println("Guess The Number Between 1 to 100 : ");
int attempts = 0;
boolean flag = true;
while (flag) {
while (attempts < limit) {
System.out.print("Enter The Number : ");
int num = sc.nextInt();
if (num == random_num) {
attempts++;
System.out.println("Right Guess......");
System.out.println("Total Attemps : " + attempts);
wins++;
flag = false;
break;
} else if (num > random_num) {
attempts++;
System.out.println("too high .....");
} else {
attempts++;
System.out.println("too low .....");
}
}
if (attempts == limit && flag == true) {
System.out.println("You Lost...limit for attempts was " + limit);
flag = false;
break;
}
}
i++;
}
System.out.println("You have won " + wins + " Round out of " + round + " Rounds");
sc.close();
}
}