|
-
Dec 13th, 2005, 03:49 PM
#1
Thread Starter
New Member
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
-
Dec 13th, 2005, 07:43 PM
#2
Re: Need Help with Simple Recursion!
Moved from CodeBank (which is for finished code samples), and mis-post deleted.
-
Dec 14th, 2005, 12:24 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|