public class FactorialFor { public static void main(String[] args) { for (int i = 1; i <= 10; i++) { long factorial = calcularFactorial(i); System.out.println("El factorial de " + i + " es: " + factorial); } }
public static long calcularFactorial(int n) {
if (n == 0) {
return 1;
} else {
long factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
}
return factorial;
}
}
}