SHARE
TWEET

Untitled

a guest Nov 19th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class GuessNumber
  4. {
  5.  
  6.   public static void main(String[] args)
  7.   {
  8.     // TODO Auto-generated method stub
  9.  
  10.     int number = (int) (Math.random() * 101);
  11.     Scanner input = new Scanner(System.in);
  12.  
  13.     System.out.print("What is your name?");
  14.     String playerName = input.next();
  15.  
  16.     System.out.println("Guess a magic number between 0 and 100");
  17.  
  18.     int guess = -1;
  19.     int guessCount = 0;
  20.  
  21.     while (guess != number)
  22.     {
  23.       System.out.print("\nEnter your guess: ");
  24.       guess = input.nextInt();
  25.       if (guess == number)
  26.       {
  27.         System.out.println("Yes, the number is " + number);
  28.         guessCount++;
  29.       }
  30.       else if (guess > number)
  31.       {
  32.         System.out.println("Your guess is too high");
  33.         guessCount++;
  34.       }
  35.       else
  36.         System.out.println("Your guess is too low");
  37.       guessCount++;
  38.  
  39.     }
  40.     System.out.println("Congratulations, " + playerName + "!");
  41.     System.out.println("You successfully guessed the correct number in "
  42.       + guessCount + " tries!");
  43.  
  44.     if (guessCount >= 4 || guessCount <= 7)
  45.     {
  46.       System.out.println(playerName + " didn't do too bad.");
  47.     }
  48.     else if (guessCount >= 8)
  49.     {
  50.       System.out.println(playerName + " is not efficient.");
  51.     }
  52.     else
  53.       System.out.println(playerName + " is an Epic Gamer!");
  54.   }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top