Advertisement
anzhelo

Untitled

Sep 25th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class NGG442087 {
  4.     public static void main(String[] args) {
  5.         new NGG442087().run();
  6.     }
  7.     public void run(){
  8.         Scanner scanner = new Scanner(System.in);
  9.         Random rand = new Random();
  10.         boolean game = false;
  11.         System.out.println("Guess the number.");
  12.         int number = scanner.nextInt();
  13.         int randomNum = 1+ rand.nextInt(10);
  14.         while(game == false) {
  15.             if(number == randomNum){
  16.                 game = true;
  17.                 System.out.println("You have guessed correctly");
  18.             } else if(number > randomNum) {
  19.                 System.out.println("Too high. Try again.");
  20.                 number = scanner.nextInt();
  21.             } else if(number < randomNum) {
  22.                 System.out.println("Too low. Try again.");
  23.                 number = scanner.nextInt();
  24.             }
  25.             System.out.println("Your number is: " + randomNum);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement