write a program in Java language to input 2 numbersand print its LCM.........plz give the answer
Answers
Answered by
0
Answer:
import java.util.Scanner;
public class LCM {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a,b,lcm;
System.out.println("enter number 1");
a=sc.nextInt();
System.out.println("enter number 2");
b=sc.nextInt();
if (a>b)
lcm=a;
else
lcm=b;
System.out.println(lcm);
for(; ;lcm++)
{
if(lcm%a==0&&lcm%b==0)
break;
else
continue;
}
System.out.println("l.c.m of two numbers is "+lcm);
}
}
Explanation:
simple logic starting from given number and checking till a number divides both
Similar questions