factorial.java
import java.util.Scanner;
public class FactorialNumero {
public static void main(String[] args) {
Scanner numero = new Scanner(System.in);
long factorial=1;
int num;
System.out.print("Introduce un número: ");
num = numero.nextInt();
for (int i = 1; i <=num; i++) {
factorial = factorial * i;
}
System.out.println("El factorial de " + num + " es: " + factorial);
}
}
public class FactorialNumero {
public static void main(String[] args) {
Scanner numero = new Scanner(System.in);
long factorial=1;
int num;
System.out.print("Introduce un número: ");
num = numero.nextInt();
for (int i = 1; i <=num; i++) {
factorial = factorial * i;
}
System.out.println("El factorial de " + num + " es: " + factorial);
}
}
Comentarios
Publicar un comentario