Welcome to the World of Online Learning:
Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a Java Program to Find LCM of two Numbers
PROGRAM: Java Program to Find LCM of two Numbers
/* Java Program to Find LCM of two Numbers*/
1: LCM using while Loop and if Statement
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n1 = 72, n2 = 120;
int gcd = findGCD(n1, n2);
int lcm = (n1 * n2) / gcd;
System.out.printf(“The LCM of %d and %d is %d.”, n1, n2, lcm);
}
public static int findGCD(int a, int b) {
if (b == 0)
return a;
return findGCD(b, a % b);
}
}
2: Calculate LCM using GCD
public class Main {
public static void main(String[] args) {
int n1 = 72, n2 = 120;
int gcd = findGCD(n1, n2);
int lcm = (n1 * n2) / gcd;
System.out.printf(“The LCM of %d and %d is %d.”, n1, n2, lcm);
}
public static int findGCD(int a, int b) {
if (b == 0)
return a;
return findGCD(b, a % b);
}
}