| | |
recursionFactorial
Thread Solved
![]() |
•
•
Join Date: Sep 2008
Posts: 91
Reputation:
Solved Threads: 1
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]
[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]
![]() |
Other Threads in the Java Forum
- Previous Thread: FileChooser
- Next Thread: Plugins
| Thread Tools | Search this Thread |
addball android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows





