Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 8, 2019 09:41
Show Gist options
  • Save 0ryant/3483c0f8c7df93704da7e56efe97440e to your computer and use it in GitHub Desktop.
Save 0ryant/3483c0f8c7df93704da7e56efe97440e to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Get Greatest Common Divisor
public static int getGreatestCommonDivisor(int first, int second){
if ((first<10)||(second<10)){
return -1;
}
int gtDivisor=1;
for (int i=2;i<=((first+second)/2);i++)
if ((first%i==0)&&(second%i==0)){
gtDivisor=i;
}
return gtDivisor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment