// Recursion example that involves a method creating new instances of the method

import javax.swing.JOptionPane;

public class Recursion2
{
public double factorial(long num)
{
    // base case
    if (num == 1)
        return 1;
    else
        return num * factorial(num-1);
}

public static void main(String[] args)
{     Recursion2 r = new Recursion2();
    String numS = JOptionPane.showInputDialog("Number? ");
    long num = Integer.parseInt(numS);
    double result = r.factorial(num);
    JOptionPane.showMessageDialog(null, num + "! = " + result);
}
}