write a program to input or two integers M and n and print the LCM of M and n in java
Answers
Answered by
0
import io.*;
class lcm
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(system.in));
int a,b,i;
int c=0;
System.out.print("Enter the first number : ");
a=Integer.parseInt(br.readLine());
System.out.print("\n");
System.out.print("Enter the second number : ");
b=Integer.parseInt(br.readLine());
System.out.print("\n");
c=a*b;
int d=c;
for(i=1;i<=c;i++)
{
if(i%a==0 && i%b==0 && i<d)
d=i;
}
System.out.println("The L.C.M : "+d);
}
}
Similar questions