package chapter34;

import javax.swing.JOptionPane;

public class ComputeFactorialIteratively {
    /** Main method */
    public static void main(String[] args) {
        // Prompt the user to enter an integer
        String intString = JOptionPane.showInputDialog(
                "Please enter a non-negative integer:");

        // Convert string into integer
        int n = Integer.parseInt(intString);

        // Display factorial
        JOptionPane.showMessageDialog(null,
                "Factorial of " + n + " is " + factorial(n));
    }

    /** Return the factorial for a specified index */
    static long factorial(int number) {
        long factorial = 1;
        for ( int counter = number; counter >= 1; counter-- )
            factorial = factorial * counter;
        return factorial;
    }
}
