SHARE
TWEET

Guess

a guest Oct 21st, 2019 94 in 148 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package javaapplication1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class JavaApplication1 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.  
  10.         int number = (int) (Math.random() * 101);
  11.         int guess;
  12.  
  13.         do {
  14.             System.out.print("Try to guess my number : ");
  15.             guess = input.nextInt();
  16.             if (guess > number) {
  17.                 System.out.println("Sorry try again!! Guess is bigger");
  18.             } else if (guess < number) {
  19.                 System.out.println("Sorry try again!! Guess is smaller");
  20.             }
  21.         } while (guess != number);
  22.         System.out.println("Correct answer");
  23.     }
  24. }
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