leer n con excepcion
This commit is contained in:
1 parent
8b3b337b03
commit
42030706b4
1 file changed
+12
-1
@@ -5,7 +5,18 @@ public class EstructuraRepetitiva3_2 {
|
||||
static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Introduce un número entero: ");
|
||||
int n = sc.nextInt();
|
||||
|
||||
int n = 0;
|
||||
try{
|
||||
n = sc.nextInt();
|
||||
} catch (Exception e) {
|
||||
System.out.println("La lectura de input ha lanzado la exception" + e + "\n");
|
||||
}
|
||||
|
||||
if (n <= 4){
|
||||
System.out.println("El numero tiene que ser mayor que 4");
|
||||
return;
|
||||
}
|
||||
|
||||
// si compuestos[n] == true, el número es compuesto
|
||||
boolean[] compuestos = new boolean[n + 1];
|
||||
|
||||
Reference in new issue
Block a user