Write a program to find LCM of two number in java

 Write a program to find LCM of two number in java

public class LCM
{
    public static void main(String args[]){
        int number1=18,number2=36,lcm;
        
        if(number1>number2){
        lcm=number1;
        }else{
        lcm=number2;
        }
        
        while(true){
            if(lcm%number1==0 && lcm%number2==0){
            System.out.println("The LCM of "+number1+" and "+number2+" is "+lcm);
            break;
            }
            lcm++;
        }
    }
}

Output
The LCM of 18 and 36 is 36

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Calculate Compound Interest in JavaScript

Write a program to find sum of first 10 natural number in java