File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
src/main/java/com/thealgorithms/puzzlesandgames Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 77package com .thealgorithms .puzzlesandgames ;
88import java .util .Scanner ;
99
10- public class NumberGuess {
10+ public final class NumberGuess {
11+ private NumberGuess () {
12+ throw new AssertionError ("Cannot instantiate NumberGuess" );
13+ }
14+
1115 public static void playGame () {
1216 Scanner sc = new Scanner (System .in );
1317 int number = (int ) (Math .random () * 100 ) + 1 ;
14- int guess = 0 , tries = 0 ;
18+ int guess = 0 ;
19+ int tries = 0 ;
1520
1621 System .out .println ("🎯 Welcome to the Number Guessing Game!" );
1722 System .out .println ("I've picked a number between 1 and 100. Try to guess it!\n " );
@@ -33,10 +38,12 @@ public static void playGame() {
3338 continue ;
3439 }
3540
36- if (guess < number )
41+ if (guess < number ) {
3742 System .out .println ("Too low! 📉" );
38- else if (guess > number )
43+ }
44+ else if (guess > number ) {
3945 System .out .println ("Too high! 📈" );
46+ }
4047 else {
4148 System .out .println ("🎉 Correct! The number was " + number + "." );
4249 System .out .println ("You took " + tries + " tries." );
You can’t perform that action at this time.
0 commit comments