I have done this program with Java, that the user has to guess the number with 5 attempts, the number is 6, but the second attempt hangs up
import java.util.Scanner;
public class Practica15 {
public static final int NUMERO_SECRETO = 6;
public static void main(String[] args) {
// TODO Auto-generated method stub
int num=0;
int intentos=5;
Scanner teclado= new Scanner(System.in);
System.out.println("Introduce un numero");
num=teclado.nextInt();
if (num==NUMERO_SECRETO && intentos<=5) {
System.out.println("El numero es correcto");
}
while (num != NUMERO_SECRETO && intentos >= 1) {
intentos--;
System.out.println("Error, el numero no es correcto, te quedan: " +
intentos + " intentos ");
teclado.nextLine();
System.out.println("Introduce el numero de nuevo");
num=teclado.nextInt();
teclado.close();
if (num==NUMERO_SECRETO && intentos <5) {
System.out.println("Correcto. Lo has conseguido en " +
intentos + " intentos");
}else if (num!=NUMERO_SECRETO && intentos==1) {
System.out.println("Has agotado los intentos");
}
}
}
}