Ejercicio 4 eficiente
This commit is contained in:
1 parent
296ce2f729
commit
8ee32e659d
1 file changed
+8
-10
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user