. Write a program in Java to find the Least Common Multiple (L.C.M.) of two
numbers entered by the user.
Answers
Answered by
2
Answer:
public class LCMofTwo1 {
private static Scanner sc;
public static void main(String[] args)
{
int Num1, Num2, Temp, GCD = 0, LCM = 0;
sc = new Scanner(System.in);
System.out.print(" Please Enter the First Integer Value : ");
Num1 = sc.nextInt();
System.out.print(" Please Enter the Second Integer Value : ");
Num2 = sc.nextInt();
int a = Num1;
int b = Num2;
while(Num2 != 0)
{
Temp = Num2;
Num2 = Num1 % Num2;
Num1 = Temp;
}
GCD = Num1;
System.out.println("\n GCD of " + a + " and " + b + " = " + GCD);
LCM = (a * b) / GCD;
System.out.println("\n LCM of " + a + " and " + b + " = " + LCM);
}
Explanation:
Similar questions
Math,
3 months ago
CBSE BOARD X,
3 months ago
Hindi,
3 months ago
Biology,
6 months ago
Biology,
6 months ago
Computer Science,
10 months ago