Buenas noches, este reto fue divertido, me gustaria recibir feedbacks para aumentar mi nivel
import java.util.Random;
import java.util.Scanner;
import java.util.InputMismatchException;
public class Desafio {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numeroRandom = new Random().nextInt(101); // 0 a 100 inclusive
int intentos = 5;
int numero = -1;
String inicio = """
Bienvenido al juego de el numero alazar del 0 al 100
Contiene 5 intentos para ganar :)
Iniciemos el juego
Digita un numero del 0 al 100:
""";
System.out.println(inicio);
while (intentos > 0) {
try {
numero = sc.nextInt();
if (numero < 0 || numero > 100) {
System.out.println("Recuerda: el número debe estar entre 0 y 100.");
intentos--;
continue;
}
if (numero == numeroRandom) {
System.out.println("Felicidades, ganaste! El número era: " + numeroRandom);
System.out.println("Intentos restantes: " + intentos);
break;
} else {
intentos--;
if (numero < numeroRandom) {
System.out.println("El número es mayor. Te quedan " + intentos + " intentos.");
} else {
System.out.println("El número es menor. Te quedan " + intentos + " intentos.");
}
}
} catch (InputMismatchException e) {
System.out.println("Entrada no válida. Debes ingresar un número.");
sc.next();
intentos--;
}
if (intentos == 0) {
System.out.println("Perdiste, el número era: " + numeroRandom);
}
}
}
}