Skip to content

hegdepavankumar/Guess-the-Number-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Guess-the-Number-Game

GitHub GitHub top language GitHub last commit ViewCount


Guess the Number Game using Java(OOPs Edition), Guess the number play with the Computer...Have a Fun!..

The task is to write a Java program in which a user will get K trials to guess a randomly generated number. Below are the rules of the game:

If the guessed number is bigger than the actual number, the program will respond with the message that the guessed number is higher than the actual number. If the guessed number is smaller than the actual number, the program will respond with the message that the guessed number is lower than the actual number. If the guessed number is equal to the actual number or if the K trials are exhausted, the program will end with a suitable message.

Approach: Below are the steps:

The approach is to generate a random number using Math. random() method in Java. Now using a loop, take K input from the user, and for each input print whether the number is smaller or larger than the actual number. If within K trials the user guessed the number correctly, print that the user won. Else print that he was not able to guess and then print the actual number.


Algorithm for Number guessing game

Step 1: Create three variables attempt, userGuessNumber, and secretNumber, and initialize them. Step 2: Generate a random number and assign it to a secret number. Step 3: Start a loop and take user input. Step 4: Validate user input and match with the secretNumber. Step 5: If userGuessNumber is greater than or less than the secretNumber then print a message to the user. Step 6: If userGuessNumber is equal to the secretNumber, then the user wins and exits the game. Step 7: If several attempts exceed the limit, exit the game. Step 8:Repeat from Step 3.

Note

The GUI version of this game is Coming Soon ...Stay tuned!.

Creator [🔝](# Guess-the-Number-Game)

(https://github.com/hegdepavankumar). This Project is Created by:-

|
@hegdepavankumar
|

           Hey Everyone Please give me a star .. and Follow me for more amazing project ideas and Updates⭐ and don't forget to fork the repo....
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Thank you~~~🙏😍~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages