Java: get greatest common divisor
As far as I know, there isn’t any built-in method for primitives. But something as simple as this should do the trick: public int gcd(int a, int b) { if (b==0) return a; return gcd(b,a%b); } You can also one-line it if you’re into that sort of thing: public int gcd(int a, int b) { … Read more