RSS Forums RSS

recursionFactorial

Please support our Java advertiser: Programming Forums
Thread Solved
Reply
Posts: 85
Reputation: ezkonekgal is an unknown quantity at this point 
Solved Threads: 1
ezkonekgal ezkonekgal is offline Offline
Junior Poster in Training

recursionFactorial

  #1  
Nov 21st, 2008
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]
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Java Forum
Views: 293 | Replies: 0 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:34 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC