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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need help with the Tracing Answer!

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 ( 
    == )                        
            return 
    x;
        else if ( 
    >= && 0)
            return 
    GCD );
        else return 
    GCD );  

    Trace the above method for x=32 and y=46


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,962
    Thanks
    56
    Thanked 2,354 Times in 2,325 Posts

    Default Re: Need help with the Tracing Answer!

    Do you have a question or problem?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 ( 
    == )                        
            return 
    x;
        else if ( 
    >= && 0)
            return 
    GCD );
        else return 
    GCD );  

    Trace the above method for x=32 and y=46

  4. #4
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,962
    Thanks
    56
    Thanked 2,354 Times in 2,325 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Apr 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with the Tracing Answer!

    I did that but it is showing error.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,962
    Thanks
    56
    Thanked 2,354 Times in 2,325 Posts

    Default Re: Need help with the Tracing Answer!

    it is showing error.
    Post the code and the full text of the error.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Answer me !
    By johnmecanse34 in forum Java Networking
    Replies: 2
    Last Post: November 20th, 2013, 06:12 AM
  2. Can any One answer it !!!!!!!!!!!!!!!!!!!!!
    By Srinivas_Java_Developer in forum Java Servlet
    Replies: 1
    Last Post: October 23rd, 2013, 01:42 PM
  3. Replies: 3
    Last Post: March 9th, 2013, 07:22 PM
  4. Can somebody help me to answer this? Thanks!
    By dshainad in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 13th, 2012, 09:47 PM
  5. Editing open source code- tracing a value set to a concrete variable
    By a_posse_ad_esse in forum What's Wrong With My Code?
    Replies: 10
    Last Post: August 21st, 2011, 06:50 PM