This week's giveaway is in the Spring forum. We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line! See this thread for details.

What formula are you trying to use to get the GCD? The code isn't right, but I don't know if you've got an incorrect implementation of the right algorithm, or a correct implementation of the wrong algorithm. At the moment you're just taking the modulus of one of the values with respect to the other, which isn't correct.

Take the example you've given: 84 and 48. Your code just calculates 84 % 48, which is 36, which isn't a common divisor of either of them. The easiest approach I know is probably the Euclidean algorithm, which uses modular arithmetic, but needs multiple calculations (so either a loop or a recursive function). The recursive calculation goes something like: