943,740 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 453
  • Java RSS
Nov 21st, 2008
0

recursionFactorial

Expand Post »
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

[code = java]
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);
}
}

}
[code]
Reputation Points: 9
Solved Threads: 1
Junior Poster
ezkonekgal is offline Offline
109 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: FileChooser
Next Thread in Java Forum Timeline: Plugins





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC