Skip to content

Instantly share code, notes, and snippets.

@enile8
Created April 20, 2013 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enile8/5426172 to your computer and use it in GitHub Desktop.
Save enile8/5426172 to your computer and use it in GitHub Desktop.
Greatest common divisor recursion example
public class GCD {
public static void main(String[] args) {
// jacked the test values from wikipedia
// output should be 37
System.out.println(gcd(259,111));
}
public static int gcd(int x, int y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment