ezkonekgal -1 Junior Poster

This is what i did for the factorial assignment that we had.. but i have a little trouble in my recursionFactorial method.. can anyone help? tnx

public class Factorial {

    public static void main(String[] args) {

        int index = JOptionPane.showConfirmDialog(null,"Would you like to compute\n" + "for the factorial of a number?","Welcome!", JOptionPane.YES_NO_OPTION);
        if (index == 0){
            String num = JOptionPane.showInputDialog(null, "Enter Number:", "Calculate Factorial", JOptionPane.PLAIN_MESSAGE);
            int number = Integer.parseInt(num);
            int result = recursionFactorial(number);
            JOptionPane.showMessageDialog(null, result);
        }else{
            JOptionPane.showMessageDialog(null, "Thank You!");
        }
    }
    public static int recursionFactorial(int number){
        if (number==0){
            return 1;
        }else{
            return number * factorial(number-1);
        }
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.