Algorithm Sample - Factorial


package algorithmsample30;

import java.util.Scanner;

/**
 *
 * @author Nurhak
 */
public class AlgorithmSample30 {

    public static void main(String[] args) {
        int number = 0;
        int factorial = 1;
        String data = "";

        try {
            Scanner scan = new Scanner(System.in);
            System.out.println("Enter the number.");
            data = scan.nextLine();
            number = Integer.parseInt(data);

            for (int i = number; i >= 1; i += -1) {
                factorial = factorial * i;
            }
            System.out.println(number + " ! = " + factorial);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Comments

Popular posts from this blog

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Solution for "Can not obtain Oracle client information from registry"