-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCM.java
More file actions
35 lines (32 loc) · 645 Bytes
/
Copy pathLCM.java
File metadata and controls
35 lines (32 loc) · 645 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
package number_Programming.medium.day_05;
import java.util.Scanner;
public class LCM
{
public static void lcm(int n1,int n2)
{
int range = 0;
if(n1<=n2)
range = n1;
else
range = n2;
int hcf =0;
for(int i = 1;i<=range;i++)
{
if(n1%i==0 && n2%i==0)
{
hcf = i;
}
}
int lcm = (n1*n2)/hcf;
System.out.println("The lcm of " + n1 + " and " + n2 + " is " + lcm);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter num1: ");
int n1 = sc.nextInt();
System.out.println("Enter num2 : ");
int n2 = sc.nextInt();
lcm(n1, n2);
sc.close();
}
}