adham-ahmed

IDE Eclipse Simple Guessing game to play in console with javascript

Apr 11th, 2022 (edited)
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. //Setting up The game
  5. //First make a new JavaProject
  6. //Then go to src and right click on it then go to new  then go to class make sure its public static void main(String[] args) {
  7. //Then put this code and enjoy:)
  8. //if you made new things and you want to debug it go to int randomNumber = rand.nextInt(100) + 1 ; and make a new line under it and put
  9. //System.out.println("The number is " + randomNumber);
  10. // to play Hit ctrl+11 annd play in the console, Enjoy:)
  11. //Also if you want to make the player can guess 10times only then put a code under int randomNumber = rand.nextInt(100) + 1 ;
  12. //Then put this code for (int i = 0; i <10; i++) { put the other "}" at the last line make sure when u put it remove while(true) { and
  13. //the other "}" at the last line
  14.  
  15.  
  16.  
  17. import java.util.Random;
  18. import java.util.Scanner;
  19. public class NumberGuessingGame {
  20.  
  21.     public static void main(String[] args) {
  22.         Random rand = new Random();
  23.        
  24.         int randomNumber = rand.nextInt(100) + 1;
  25.    
  26.             while(true) {
  27.                
  28.            
  29.        
  30.        
  31.         System.out.println("Enter your guess(1-100):");
  32.        
  33.         Scanner scanner = new Scanner(System.in);
  34.         int playerGuess = scanner.nextInt();
  35.         if (playerGuess == randomNumber) {
  36.             System.out.println("Correct! You Won!");
  37.             break;
  38.         }
  39.         else if (randomNumber > playerGuess) {
  40.             System.out.println("False.. The number is higher. Guess again");
  41.         }
  42.         else {
  43.             System.out.println("False.. The number is lower. Guess again:");
  44.         }
  45.     }
  46.            
  47.     }
  48. }
  49.  
Add Comment
Please, Sign In to add comment