3 Replies - 4423 Views - Last Post: 28 February 2010 - 05:35 PM Rate Topic: -----

#1 luron31  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 19-July 09

Explanation for GCD while loop

Posted 22 February 2010 - 11:14 AM

Can someone explain this code line by line?

the int B is supposed to b
 
public static int gcd(int a, int B)/>
  {
        int gcd;
       while (b != 0)
      {
             int temp = a % b;
             a = b;
             b = temp;
     }
      gcd =  Math.abs(a);
      return gcd;
  }


This post has been edited by luron31: 22 February 2010 - 11:19 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Explanation for GCD while loop

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9156
  • View blog
  • Posts: 33,975
  • Joined: 27-December 08

Re: Explanation for GCD while loop

Posted 22 February 2010 - 01:36 PM

Yes- B should be lowercased. Also, this sounds like a homework assignment. Is there a specific part you are unsure about? If so, can you talk us through what you do understand, what you think each part does, and what you are unsure about?
Was This Post Helpful? 0
  • +
  • -

#3 luron31  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 19-July 09

Re: Explanation for GCD while loop

Posted 28 February 2010 - 01:34 PM

View Postmacosxnerd101, on 22 February 2010 - 12:36 PM, said:

Yes- B should be lowercased. Also, this sounds like a homework assignment. Is there a specific part you are unsure about? If so, can you talk us through what you do understand, what you think each part does, and what you are unsure about?


Nevermind. Thanks
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: Explanation for GCD while loop

Posted 28 February 2010 - 05:35 PM

public static int gcd(int a, int B)/> 
  { 
        int gcd; 


even if legal because the compiler is smart NEVER NEVER NEVER a good idea to have a method() and a variable with the same name. Here: gcd
It is just make things more confusing
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1