Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Need help with the Tracing Answer!

Consider the following recursive method that calculates the greatest common divisor using Euclidean method.

PHP Code:
``` public static int GCD ( int x , int y ) {     if ( y == 0 )                                 return x;     else if ( x >= y && y > 0)         return GCD ( y , x % y );     else return GCD ( y , x );   }  ```
Trace the above method for x=32 and y=46

2. ## Re: Need help with the Tracing Answer!

Do you have a question or problem?

3. ## Need help with the Tracing Answer!

This a question from my Assignment - I have to trace the answer.
As far as I can understand I think it should be GCD (46, 36). Is this right?

As x value is less than y.
----------------------------------------------------------
Consider the following recursive method that calculates the greatest common divisor using Euclidean method.

PHP Code:
``` public static int GCD ( int x , int y ) {     if ( y == 0 )                                 return x;     else if ( x >= y && y > 0)         return GCD ( y , x % y );     else return GCD ( y , x );   }  ```
Trace the above method for x=32 and y=46

4. ## Re: Need help with the Tracing Answer!

Yes! I'm confused weather if I'm getting a right answer. I think it is GCD (46, 36). Is this right?

5. ## Re: Need help with the Tracing Answer!

I'm not sure what you mean by the "right answer". The GCD method returns an int value.
Trace the above method for x=32 and y=46
What is returned for x=32 and y=46? Compile and execute the code to see what is returned.

6. ## Re: Need help with the Tracing Answer!

I did that but it is showing error.

7. ## Re: Need help with the Tracing Answer!

it is showing error.
Post the code and the full text of the error.