- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJava.java
More file actions
Latest commit
24 lines (21 loc) · 589 Bytes
/
Copy pathJava.java
File metadata and controls
24 lines (21 loc) · 589 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
importjava.util.Scanner;
publicclassJava {
publicstaticvoidmain(String[] args) {
inta = (int) (Math.random() * 102);
intattempts = 0;
ScannermyObj = newScanner(System.in);
while (true) {
System.out.println("Guess a number from 0 to 102:");
intguess = myObj.nextInt();
attempts++;
if (guess < a) {
System.out.println("Too low!");
} elseif (guess > a) {
System.out.println("Too High!");
} else {
System.out.println("Correct! You took " + attempts + " guesses.");
break;
}
}
}
}