Results 1 to 3 of 3

Thread: Need Help with Simple Recursion!

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    1

    Need Help with Simple Recursion!

    I'm trying to get this simple recursion method figured out and I'm having a tough time. What this function is supposed to do is accept 2 arguments into parameters x and y and then give back the value of x times y. How do I do this?? I know I have to use addition somehow since it is recursion! Any help would be appreciated! Thanks!
    Phil

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Need Help with Simple Recursion!

    Moved from CodeBank (which is for finished code samples), and mis-post deleted.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Need Help with Simple Recursion!

    Code:
      public static int multiply(int x, int y) {
        if (y == 1) {
          return x;
        }
        else {
          return x + multiply(x, y - 1);
        }
      }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width