Skip to content

Commit 888813f

Browse files
committed
Create LCM.java
1 parent f720bc3 commit 888813f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

JavaBook/NumberThoery/LCM.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class LCM {
2+
public static int gcd(int a, int b){
3+
if(b==0){
4+
return a;
5+
}
6+
return gcd(b, a%b);
7+
}
8+
public static void main(String[] args){
9+
int a = 10;
10+
int b = 20;
11+
int result = lcm(a, b);
12+
System.out.println("GCD of " + a + " and " + b + " is: " + gcd(a, b));
13+
System.out.println("LCM of " + a + " and " + b + " is: " + result);
14+
}
15+
public static int lcm(int a, int b){
16+
return (a*b)/gcd(a,b);
17+
}
18+
}

0 commit comments

Comments
 (0)