Compare commits

..
4 Commits
Author SHA1 Message Date
PC de clase 42030706b4 leer n con excepcion 2026-10-22 13:15:54 +02:00
PC de clase 8b3b337b03 corregir longitud de enteros en multiplicacion 2026-10-22 12:59:54 +02:00
PC de clase 5129dd9415 poner diferencai de peso 2026-10-22 12:58:06 +02:00
PC de clase 8ee32e659d Ejercicio 4 eficiente 2026-10-22 12:52:37 +02:00
4 changed files with 23 additions and 12 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ public class EstructuraRepetitiva2 {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
System.out.printf("%2d x %2d = %3d\n", i, j, i*j);
System.out.printf("%2d x %2d = %2d\n", i, j, i*j);
}
System.out.println("--------------");
}
+12 -1
View File
@@ -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];
+8 -10
View File
@@ -6,19 +6,17 @@ public class EstructuraRepetitiva4 {
System.out.println("Introduce un número entero: ");
int n = sc.nextInt();
for (int i = 3; i <= n; i++) {
for (int i = 3; i <= n; i+=3) {
boolean primero = true; // Para poner la , bien
if (i % 3 == 0) {
System.out.printf("Múltiplo=%d divisores del %d: (", i, i);
for (int j = 1; j <= i; j++) {
if (i % j == 0) {
if (!primero) System.out.print(",");
System.out.printf("%d", j);
primero = false;
}
System.out.printf("Múltiplo=%d divisores del %d: (", i, i);
for (int j = 1; j <= i; j++) {
if (i % j == 0) {
if (!primero) System.out.print(",");
System.out.printf("%d", j);
primero = false;
}
System.out.print(")\n");
}
System.out.print(")\n");
}
sc.close();
}
+2
View File
@@ -21,8 +21,10 @@ public class EstructuraRepetitiva5 {
}
if (carga >= CARGA_MAXIMA) {
System.out.println("El camión ha alcanzado el peso máximo");
System.out.printf("Te has pasado por %.2fKg\n", CARGA_MAXIMA - carga);
} else {
System.out.println("El mueble ya no cabe en el camión");
System.out.printf("Te has pasado por %.2fm3\n", VOLUMEN_MAXIMO - volumen);
}
}
}