Advertisement
Sampywise

Number Guessing Game

Jul 9th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import java.util.Scanner; //imports a thing
  2.  
  3. public class LessonFive {
  4.     public static void main(String []args) {
  5.         int Num;
  6.         Num = (int) (Math.random() * 999 + 1);
  7.         //the above make Num somewhere between 1 and 1000
  8.         Scanner keyboard = new Scanner(System.in);
  9.         int guess = -1;
  10.        
  11.         while (guess != Num) {
  12.             System.out.print("Enter a guess:  ");
  13.             guess = keyboard.nextInt();
  14.             //allows the user to guess a number
  15.             System.out.println(guess);
  16.            
  17.             if(guess == Num) {
  18.                 System.out.println("You're rignt!!");
  19.             }
  20.             if(guess < Num) {
  21.                 System.out.println("Too low!");
  22.             }
  23.             if(guess > Num) {
  24.                 System.out.println("Too high!");
  25.             //tells user if too high, too low, or correct
  26.             }
  27.         }
  28.     }
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement