From b7efcfcc7ae298e926942cf458a838b2d6f4b6bc Mon Sep 17 00:00:00 2001 From: Maciej Uniejewski Date: Sat, 13 Oct 2018 11:43:08 +0200 Subject: [PATCH 1/2] Add LCM calculating for Mathematics module. --- Java/Mathematics/LCM.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Java/Mathematics/LCM.java diff --git a/Java/Mathematics/LCM.java b/Java/Mathematics/LCM.java new file mode 100644 index 000000000..f9a28621e --- /dev/null +++ b/Java/Mathematics/LCM.java @@ -0,0 +1,4 @@ +package Mathematics; + +public class LCM { +} From 3c101c6a135a2d25f9422c299d37c96a42270e13 Mon Sep 17 00:00:00 2001 From: Maciej Uniejewski Date: Sat, 13 Oct 2018 11:46:44 +0200 Subject: [PATCH 2/2] Update the LCM code. --- Java/Mathematics/LCM.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Java/Mathematics/LCM.java b/Java/Mathematics/LCM.java index f9a28621e..48fa0d7ec 100644 --- a/Java/Mathematics/LCM.java +++ b/Java/Mathematics/LCM.java @@ -1,4 +1,19 @@ package Mathematics; +import static Mathematics.EuclidGCD.gcd; + +/** + * Calculates lowest common multiple for given integer numbers + */ public class LCM { + public static void main(String[] args) { + System.out.println(lcm(2, 5)); + System.out.println(lcm(15, 3)); + System.out.println(lcm(75, 10)); + } + + public static int lcm(int a, int b) { + return a * b / gcd(a, b); + } + }