Last active
July 26, 2020 12:30
-
-
Save dvt32/0ae5a7da63d2b11ce3b4d3f60e14f461 to your computer and use it in GitHub Desktop.
ALGORITHMO #10 - Least Common Multiple 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
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