I was not sure if I should write the GCD method by myself or if I could use an already implemented method.

Of course I read about The Euclidean GCD algorithm because I am too lazy to search it in the Tec library. And this is also interesting, the pseudo-code algorithm and a formal proof of correctness from proofwiki.

This recursive algorithm is basically a method for finding the greatest common divisor of two integers. So you take two integers *a *and *b* such that |*a*| > |*b*|, then you calculate the remainder, call it *r,* of *a/b*. Next, set *a = b *and *b = r*

And i was writing the GCD class, but then I told myself:

Why should I write this if someone else has already did?

And of course also because this class is about Object Oriented Programming and not about Algorithms, and also, that’s one of the big advantages of OOP, you can use someone else’s code without worrying if your code will be compatible with other persons’ code, because it should

And after all these philosophical thoughts I decided to keep it simple and just use the BigInteger java class I found here get gcd java and here Big Integer Class.

I also pushed it to GitHub here: WSQ06-GCD.

### Like this:

Like Loading...