• Lenguaje

    Java

  • Descripción

    Mustra el factorial de un número entero positivo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

public class Factorial {

    public static void main(String[] args) throws UnsupportedEncodingException {
        Scanner in = new Scanner(System.in);
        int i, numero;
        long factorial=1;
        PrintStream out = System.out;
        if(!System.getProperties().get("os.name").equals("Linux") && System.console()!=null)
            out =  new PrintStream(System.out, true, "CP850");
        out.print("Ingrese un n\u00FAmero: ");
        numero = in.nextInt();
        out.print("\n" + numero + "! = 1");
        for (i=2; i<=numero; i++) {
            factorial *= i;
            out.print(" \u00D7 " + i);
        }
        out.println(" = " + factorial + "\n");
    }

}