Created
August 8, 2019 09:41
-
-
Save 0ryant/3483c0f8c7df93704da7e56efe97440e to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Get Greatest Common Divisor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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