# Least Common Multiple Program in Java

## The least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b.

```
import java.util.Scanner;
public class LCMProgram
{
public static void main(String[] args)
{
int a, b, gcd = 1, lcm = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a=");
a = sc.nextInt();
System.out.print("Enter b=");
b = sc.nextInt();
int min, max;
min = a;
if (min > b)
{
min = b;
max = a;
}
else
{
min = a;
max = b;
}
while (max > min)
{
int r = max % min;
if (r == 0)
{
gcd = min;
break;
}
else
{
max = min;
min = r;
}
}
lcm = (a * b) / gcd;
System.out.println("LCM:" + lcm);
}
}
```

#### Output:

Enter a=15 Enter b=18 LCM:90b. tech. bca icse java java tutorials learn java mca programs

### Frequently Asked Questions

##### What is Least Common Multiple?

The least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b.

##### What is Least Common Multiple in Java?

The least common multiple, lowest common multiple, or smallest common multiple of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b.

**Recent Posts**

- Capricorn or Kaprekar Number Program in Java October 16, 2021
- LCM and HCF of two numbers Program in C October 6, 2021
- Find day of week from a given date Program in C October 6, 2021
- Difference of two dates in years, months, days Program in C October 6, 2021
- Check whether a date is valid or not Program in C October 6, 2021
- Menu driven Program in C October 6, 2021
- Vowel or consonant Program in C October 6, 2021
- Perform arithmetic calculations on integers Program in C October 6, 2021
- Multiply two positive numbers without using "*" operator October 6, 2021
- Count digits Program in C October 6, 2021
- Product of digits Program in C October 6, 2021
- Print numbers from 1 to 10 using while loop Program in C October 6, 2021
- Find out the grade of a student Program in C October 6, 2021
- Binary Search Program in C October 2, 2021
- Employee Salary Based Program in Java September 10, 2021
- Decimal to Binary Number Program in Java July 3, 2021
- Binary to Decimal Number Program in Java July 3, 2021
- Find biggest number from three given numbers Program in C July 2, 2021
- Find quotient and remainder Program in C July 2, 2021
- Print a message if negative number is entered Program in C July 2, 2021