Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dvt32/11095d95b828c7b6042ceb757c23ef5d to your computer and use it in GitHub Desktop.
Save dvt32/11095d95b828c7b6042ceb757c23ef5d to your computer and use it in GitHub Desktop.
ALGORITHMO #1 - Euclidean Algorithm Implementation
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