Skip to content

Commit 3ced69f

Browse files
Number Guessing Game.java
1 parent 13d6a85 commit 3ced69f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Number Guessing Game.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.*;
2+
3+
public class GuessGame {
4+
public static void main(String[] args) {
5+
Random r = new Random();
6+
int num = r.nextInt(100) + 1;
7+
8+
Scanner sc = new Scanner(System.in);
9+
int guess = 0;
10+
11+
while (guess != num) {
12+
System.out.print("Guess number (1–100): ");
13+
guess = sc.nextInt();
14+
15+
if (guess < num) System.out.println("Too low!");
16+
else if (guess > num) System.out.println("Too high!");
17+
else System.out.println("Correct!");
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)