I am doing a program, it is asked to enter 3 data, if the 3 are incorrect the program ends, I do a loop do / while and asks for the 3 data the problem is that the program does not finish and passes to analyze the following condition , how do I end it after entering 3 erroneous data?
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int edad = 0;
int edad_max = 14;
int edad_min = 7;
int id;
int id_max = 2000;
int id_min = 1;
int Intents = 3;
int i = 0;
int j=0;
int intents_totals=0;
boolean correcto = true;
do {
//llegim si es correcte
System.out.println("digam ID:");
correcto = scan.hasNextInt();
if (correcto) {
id = scan.nextInt();
if ((id < 1) || (id > 1000)) {
correcto = false;
System.err.println("id incorecte, torni a introduirlo: ");
}
}
//System.err.println("el numero te que ser sencer,torni a teclejarlo");
i++;
} while ((!correcto)&&(i < 3));
// aqui deberia finalizar si los 3 intentos hemos introducido dato incorrecto
// pero salta al siguiente do while
do {
i = 0;
System.out.println("digam l´edad");
correcto = scan.hasNextInt();
if (correcto) {
edad = scan.nextInt();
if (edad < edad_min || edad > edad_max) {
correcto = false;
System.err.println("edad incorrecte, torni a introduirla");
}
}
scan.nextLine();
i++;
} while (!correcto && i < Intents);