InserimentoNumero

This commit is contained in:
La Programmatrice Verde 2025-09-30 21:33:37 +02:00
parent c2102b709d
commit c326b1ec2f

View File

@ -4,6 +4,7 @@
*/ */
package sequenzanumeri; package sequenzanumeri;
import java.util.InputMismatchException;
import java.util.Scanner; import java.util.Scanner;
/** /**
@ -74,4 +75,23 @@ public class SequenzaNumeri {
System.out.println("Premere un tasto per continuare. . ."); System.out.println("Premere un tasto per continuare. . .");
sc.nextLine(); sc.nextLine();
} }
static int InserimentoNumero() {
int ritorno = 0;
boolean error = false;
do{
System.out.println("Inserire un numero: ");
try{
ritorno = sc.nextInt();
}
catch (InputMismatchException e) {
System.out.println("Numero non valido.");
Pausa();
error = true;
}
}
while (error);
return ritorno;
}
} }