Advertisement
AnindyaBiswas

Random no

Apr 27th, 2022 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.math.*;
  2.  
  3. import java.util.Scanner;
  4. public class Rando {
  5.     public static void main(String args[])
  6.     {
  7.         Scanner sc = new Scanner(System.in);
  8.         int random_no = (int)(Math.random()*10 +1);
  9.         boolean flag = true;
  10.         //System.out.print(random_no);
  11.         while(flag)
  12.         {
  13.             System.out.print("\nEnter your guess (between 1-10) : ");
  14.             int inp = sc.nextInt();
  15.             if(inp == random_no)
  16.             {
  17.                 System.out.println("\n\tYou guessed it right!");
  18.                 flag = false;
  19.             }
  20.             else if(inp < random_no)
  21.                 System.out.println("\n Too Low!");
  22.             else
  23.                 System.out.println("\n Too High!");
  24.         }
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement