-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCM.java
More file actions
51 lines (36 loc) · 722 Bytes
/
LCM.java
File metadata and controls
51 lines (36 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class LCM {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
System.out.println (lcm(a,b));
}
private static long gcd(long a, long b) {
// TODO Auto-generated method stub
if(b == 0)
return a;
while (b !=0)
{
a = a % b;
return gcd(b,a);
}
return b;
}
private static long lcm (long a, long b)
{
long temp;
long product;
long lc;
if(b==0)
return 0;
else
{
temp = gcd (a,b);
product = a * b;
lc = product/temp;
return lc;
}
}
}