-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessGame.java
More file actions
36 lines (25 loc) · 800 Bytes
/
GuessGame.java
File metadata and controls
36 lines (25 loc) · 800 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
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
public class GuessGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random rand = new Random();
int number = rand.nextInt(100) + 1;
//*System.out.println("Secret number: " + number);
while (true) {
System.out.print("Enter your guess: ");
int guess = sc.nextInt();
int diff = Math.abs(number - guess);
if (guess == number) {
System.out.println("Correct! You guessed the number.");
break;
}
else if (diff <= 10) {
System.out.println("Hot");
}
else {
System.out.println("Cold");
}
}
sc.close();
}
}