import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n1;
do {
try {
System.out.println("Factorizar nº: 0 para salir");
n1 = Integer.parseInt(br.readLine());
if (n1 > 0) {
System.out.println("Los valores son:");
factorizar(n1);
} else if (n1 == 0) {
System.out.println("Me despido!");
} else {
System.out.println("Los valores han de ser mayor que 0");
}
} catch (IOException | NumberFormatException e) {
System.out.println("Sólo se admiten números Naturales y en el rango INT");
n1 = -1;
}
} while (n1 != 0);
}
private static void factorizar(int n1) {
for (int x = n1; x > 0; x--) {
if (esDivisible(n1, x)) {
System.out.println(x);
}
}
}
private static boolean esDivisible(int n1, int x) {
return n1 % x == 0;
}
}
[/aux_code]
Factorizar
con
No hay comentarios
[aux_code language=»javascript» theme=»tomorrow» title=»Factorizar» extra_classes=»»]