Created
December 2, 2016 11:56
-
-
Save dvt32/11095d95b828c7b6042ceb757c23ef5d to your computer and use it in GitHub Desktop.
ALGORITHMO #1 - Euclidean Algorithm Implementation
This file contains 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
import java.util.Scanner; | |
public class Solution { | |
public static int getGreatestCommonDivisor(int a, int b) { | |
if (a == b) { | |
return a; | |
} | |
while (a != b) { | |
if (a > b) { | |
a = a - b; | |
} | |
else { | |
b = b - a; | |
} | |
} | |
int greatestCommonDivisor = a; | |
return greatestCommonDivisor; | |
} | |
public static void main(String[] args) { | |
Scanner read = new Scanner(System.in); | |
int a = read.nextInt(); | |
int b = read.nextInt(); | |
int greatestCommonDivisor = getGreatestCommonDivisor(a, b); | |
System.out.println(greatestCommonDivisor); | |
// Close scanner | |
read.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment