Create a Java program Where number is generated between 1-100 guess the number until you find it!!🔥

Mini Project


Generate a  random number  between 1-100 Ask the user to guess the number Until the user Find it.If the user fails to find the number use -1 to check what the number was generated.

Code in java Language:-


import java.lang.Math;

import java.util.Scanner;

 class project{

public static void main(String[] args){

Scanner sc= new Scanner(System.in);

int ran=(int)(Math.random()*100);

int user_num;

int i;

while(true){

user_num=sc.nextInt();

if(user_num==-1){

System.out.println("Random number "+ran);

break;

}

if(ran==user_num){

System.out.println("Great!you find the number is " +ran);

break;

}

else if(user_num<ran){

System.out.println("Sorry!the number is input less");

}

else if(user_num>ran){

System.out.println("Sorry!the number is input more");

            }

        }

    }

}


Output:-





ThankYou!Keep Learning..🔥



Comments

Popular posts from this blog

4 digit OTP Generator!!

Novak Djokovic's 21-match Davis Cup win streak comes to end

US-Canada bridge expected to reopen in day or two, says mayor Jim Diodati