import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner (System.in);
      Random rn = new Random ();
      
     
        System.out.println("Guess a number");
        System.out.println("do you want to play this game ");
        String yesno = sc.next();
        
        if (yesno.equalsIgnoreCase("yes"))
       {
           
        int rdnum = rn.nextInt(10);
        // 10 isliye kyuki ye 0 se ,10 tk no. generate krega bss
        
        System.out.println("Ok lets a guess a number 1 to 10 \nWhat am i think");
        int try1 = sc.nextInt();
     
     
     
    do  { 
           if (try1==rdnum)
       {
         System.out.println("congratulations you guess right \n I think "+rdnum);
         break;
       } 
      
          else if (try1>rdnum)
      {  
          System.out.println("think lower number");
       
      }
      
          else if (try1<rdnum)
      {
        System.out.println("higher number ");
      
      } 
  
  
    }   while (try1!=rdnum);
   
   
   
   
   
   
   
    
    
    
       } // 1st if brac
      else if (yesno.equalsIgnoreCase("no"))
  
      System.out.println("thanks for your valuable time");
     else 
     System.out.println("invalid input [ yes or no]");
        
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: