Skip to content

Commit 46b296c

Browse files
authoredMar 20, 2023
Create lcm.java
1 parent 7fada4d commit 46b296c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎lcm.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class lcm {
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)