Computer Science, asked by Purujeet, 1 year ago

Write a program in Java to accept the 2numbers and find the LCM of 2numbers

Answers

Answered by maria9
0
import java.util.*;
class lcm
{
public static void main()
{
scanner sc=New scanner(system.in);
system.out.print("enter two numbers")
int a,b max,min,x,I;

a = sc. nextInt();
b = sc.nextInt();

if (a>b)
{
max = a;
min=b;
}
if(b>a)
{
max=b;
min=a;
}
for (i=1;i<=min;i++)
{
x=max*i;
if(x%min==0)
{
lcm = x;
break;
}
}
System.out.print("lcm="+lcm);
}
}
Similar questions