xxxxxxxxxx
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
/*
Write a program that generates a random number and asks the user to guess what the number is.
If the user's guess is higher than the random number,
the program should display "Too high, try again."
If the user's guess is lower than the random number,
the program should display "Too low, try again."
The program should use a loop that repeats until the user correctly guesses the random number.
(use Random class , random range 0-100)
*/
Scanner scan = new Scanner(System.in);
Random random = new Random();
int randomNum = random.nextInt(100);
while(true){
System.out.println("Enter the number : ");
int num = scan.nextInt();
if(num < randomNum){
System.out.println("Your number is less than random number , try again ");
} else if (num == randomNum) {
System.out.println("Congratulations , you find it !");
break;
}
else{
System.out.println("Your number is higher than random number , try again");
}
}
}
}