In: Computer Science
Java
It would be nice if you use many Functions.
import java.util.*;
public class FindLcm
{
public static void main (String[] args) throws
java.lang.Exception
{
Scanner sc=new
Scanner(System.in);
System.out.println("Enter two
numbers : ");
int n=sc.nextInt();
int m=sc.nextInt();
int l=LCM(n,m);
System.out.println("Lcm of "+n+"
and "+m+" is "+l);
}
public static int LCM(int num1,int num2)
{
int lcm=0,m;
m = (num1 > num2) ? num1 :
num2;
for(int i=0;i<m;i++)
{
if(m%num1==0 && m%num2==0)
{
lcm=m;
break;
}
m++;
}
return lcm;
}
}
OUTPUT:-
// If any doubt please comment