-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrect_no_choose.java
More file actions
48 lines (37 loc) · 1.62 KB
/
correct_no_choose.java
File metadata and controls
48 lines (37 loc) · 1.62 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
import java.util.Random;
import java.util.Scanner;
public class correct_no_choose {
public static void main(String[] args) {
System.out.println("Please Enter your choice between from 1 to 200");
Scanner sc = new Scanner(System.in);
Random rand = new Random();
// random number genrate 1 to 200
int computerChoice = rand.nextInt(1, 200);
// System.err.println("computer choice : " + computerChoice);
System.out.print("Take number form user : ");
// take user input
int userChoice = sc.nextInt();
int count = 1;
if (computerChoice == userChoice) {
System.out.println("User won!!! number of try chances : " + count);
} else if (computerChoice > userChoice) {
System.out.println("Enter greater number please!!!");
} else if (computerChoice < userChoice) {
System.out.println("Enter smaller number please!!!");
}
while (computerChoice > userChoice || computerChoice < userChoice) {
count+=1;
System.out.print("Enter number : ");
userChoice = sc.nextInt();
if (computerChoice > userChoice) {
System.out.println("Enter greater number please!!!");
} else if (computerChoice < userChoice) {
System.out.println("Enter smaller number please!!!");
} else {
System.out.println("user won!!!");
}
}
System.out.println("total number of try chances : " + count);
sc.close();
}
}