Skip to content

Commit 6c9d83f

Browse files
committed
added url of algos and formatted
1 parent 14b3b2b commit 6c9d83f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/com/thealgorithms/puzzlesandgames/NumberGuess.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
/**
2+
* Simple Number Guessing Game.
3+
* The player guesses a random number between 1 and 100.
4+
* Reference: https://en.wikipedia.org/wiki/Guess_the_number
5+
*/
6+
17
package com.thealgorithms.puzzlesandgames;
28
import java.util.Scanner;
39

410
public class NumberGuess {
511
public static void playGame() {
612
Scanner sc = new Scanner(System.in);
7-
int number = (int)(Math.random() * 100) + 1;
13+
int number = (int) (Math.random() * 100) + 1;
814
int guess = 0, tries = 0;
915

1016
System.out.println("🎯 Welcome to the Number Guessing Game!");
1117
System.out.println("I've picked a number between 1 and 100. Try to guess it!\n");
1218

1319
while (true) {
1420
System.out.print("Enter your guess: ");
15-
21+
1622
if (!sc.hasNextInt()) {
1723
System.out.println("Please enter a valid number.");
1824
sc.next();
@@ -45,4 +51,4 @@ public static void main(String[] args) {
4551
playGame();
4652
System.out.println("\nThanks for playing! 👋");
4753
}
48-
}
54+
}

0 commit comments

Comments
 (0)