Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

recursion how does this code work??

807599Feb 15 2007 — edited Feb 15 2007
hi im new to recursion and i was just wondering if someone could just step through how this bit of code gets the outcome that it does....
public static int mult(int m, int n)
{
//precondition m,n >=0
//postcondition: the method has returned the product of m and n

if (m==0) return 0;
else return mult(m/2, n*2) + (m%2) * n;
thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2007
Added on Feb 15 2007
12 comments
163 views