Results 1 to 4 of 4
  1. #1
    syntrax is offline Member
    Join Date
    Sep 2009
    Location
    http://www.kouje.com
    Posts
    16
    Rep Power
    0

    Smile 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 :(

    Java 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 ) );
      }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    syntrax is offline Member
    Join Date
    Sep 2009
    Location
    http://www.kouje.com
    Posts
    16
    Rep Power
    0

    Default

    i know, but that's wat the instructor wants.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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/

Similar Threads

  1. Recursive Counting
    By zlwilly in forum New To Java
    Replies: 1
    Last Post: 01-29-2009, 08:42 PM
  2. Understanding this recursive function
    By LifeWithJava in forum New To Java
    Replies: 3
    Last Post: 12-30-2008, 05:26 AM
  3. Recursive Method
    By bluegreen7hi in forum New To Java
    Replies: 5
    Last Post: 11-29-2007, 04:45 AM
  4. Recursive Anagram
    By zoe in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 06:15 AM
  5. Help with recursive implementation
    By toby in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •