- Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathFind_Number.java
More file actions
Latest commit
25 lines (24 loc) · 699 Bytes
/
Copy pathFind_Number.java
File metadata and controls
25 lines (24 loc) · 699 Bytes
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
importjava.util.*;
publicclassFind_Number {
publicstaticvoidmain(String[] args) {
intrandNo, inputNo, userAttempt = 1;
Scannerscan = newScanner(System.in);
Randomrand = newRandom();
randNo = rand.nextInt(101);
System.out.println("Guess the number between 1 to 100\n");
do {
inputNo = scan.nextInt();
if (inputNo > randNo) {
System.out.println("Lower number!!");
}
if (inputNo < randNo) {
System.out.println("Higher number!!");
}
if (inputNo == randNo) {
System.out.println("Correct!!");
System.out.println("You guessed in " + userAttempt + " attempts.");
}
userAttempt++;
} while (inputNo != randNo);
}
}