basic help with Recursive

• 12-15-2009, 06:56 AM
syntrax
basic help with Recursive
I'm trying to use Recursive, I know how to use it and i understand it, but the problem i have is that i have to use 2 input variables, and I don't know how to mix them both.

My program should take a number, add an exponential number (user inputed) and do the math.
This program work, but i have no idea where to add the 2nd input. help pls :(

Code:

```import java.util.Scanner; public class testing1 {   public static void main( String [] args )   {           int num1, num2, answer;           Scanner kb = new Scanner(System.in);                     // Get number.           System.out.print("Enter number: ");           num1 = kb.nextInt();                     // Get exponential number.           System.out.print("Enter exponential number: ");           num2 = kb.nextInt();               // compute and output it.     System.out.println(num1 + "^" + num2+ " is: " + factorial(num1));   }     public static int factorial( int n )   {     if ( n <= 0 )  // base case     return 1;     else    // general case     return ( n * factorial ( n - 1 ) );   } }```
• 12-15-2009, 06:59 AM
Fubarable
I don't see a need for factorialization here, but rather a power function.
• 12-15-2009, 07:09 AM
syntrax
i know, but that's wat the instructor wants.
• 12-15-2009, 07:19 AM
Fubarable
This doesn't make sense on two grounds:
1) The equation shown is a power equation, and
2) A factorialization method by its nature always takes one and only one parameter.

Are you sure that you didn't misread or mis-interpret the instructions/