LCM program in java:

Why LCM use in java:

In arithmetic, the Least Common Multiple (LCM) of two or more numbers is the least positive number that can be divided by both the numbers, without leaving the remainder. It is also known as Lowest Common Multiple (LCM), Least Common Denominator, and Smallest Common Multiple.

Example program :

public class Lcm 
{
public static void main(String[] args)
{
	
int no1 = 4,no2 = 15;//4 8 12 ...... 40 44 48 52 56 60 
	//64 68 72 76 80 84 88 92 96 100 104 108 112 116 120  int big = no1>no2?no1:no2;  //4>15  4:15  //15 30 45 60 75 90    
                            105 120 135 150
while(true)            //lcm - 60 120
{
if(big%no1 ==0 && big%no2==0)
{	
System.out.println("LCM "+ big); 
break;
}
big++; 
} 
}
}

output:

Leave a Comment