Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dvt32/0ae5a7da63d2b11ce3b4d3f60e14f461 to your computer and use it in GitHub Desktop.
Save dvt32/0ae5a7da63d2b11ce3b4d3f60e14f461 to your computer and use it in GitHub Desktop.
ALGORITHMO #10 - Least Common Multiple Algorithm Implementation
public class Solution {
static int getGreatestCommonDivisor(int a, int b) {
while (b != 0) {
int temp = a;
a = b;
b = temp % b;
}
int greatestCommonDivisor = a;
return greatestCommonDivisor;
}
// Get LCM
static int getLeastCommonMultiple(int a, int b) {
int leastCommonMultiple = (a * b) / getGreatestCommonDivisor(a, b);
return leastCommonMultiple;
}
public static void main(String[] args) {
System.out.println(
getLeastCommonMultiple(6, 21)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment