Skip to content

Commit f061431

Browse files
authored
Create LCM.java
This is a stand-alone LCM implementation w/o using gcd in java.
1 parent 14aa9a9 commit f061431

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Mathematics/LCM/LCM.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
4+
int n1 = 72, n2 = 120, lcm;
5+
6+
// maximum number between n1 and n2 is stored in lcm
7+
lcm = (n1 > n2) ? n1 : n2;
8+
9+
// Always true
10+
while(true) {
11+
if( lcm % n1 == 0 && lcm % n2 == 0 ) {
12+
System.out.printf("The LCM of %d and %d is %d.", n1, n2, lcm);
13+
break;
14+
}
15+
++lcm;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)