SHARE
TWEET

Untitled

a guest Sep 20th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.util.Random;
  3. import java.util.Scanner;
  4.  
  5. public class GuessingNumberGame {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner reader = new Scanner(System.in);
  9.         int numberDrawn = drawNumber();
  10. int getal = 0;
  11.         System.out.println(numberDrawn);
  12.  
  13.        
  14.         while (getal != numberDrawn) {
  15.             System.out.println("Guess a number: ");
  16.             getal = Integer.parseInt(reader.nextLine());
  17.             drawNumber();
  18.            
  19.             if (getal < numberDrawn) {
  20.                 System.out.println("The number is greater.");
  21.             } else if (getal > numberDrawn) {
  22.                 System.out.println("The number is lesser.");
  23.             } else {
  24.                 System.out.println("Congratulations, your guess is correct!");
  25.             }
  26.             }
  27.         }
  28.    
  29.    
  30.  
  31.     // DO NOT MODIFY THIS!
  32.     private static int drawNumber() {
  33.         return new Random().nextInt(101);
  34.     }
  35. }
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
 
Top