Java program to find LCM of two numbers

public class LCMOfTwoNumbers
{
   public static void main(String[] args)
   { 
      int num1 = 85, num2 = 175, lcm;
      lcm = (num1 > num2) ? num1 : num2;
      while(true)
      {
         if(lcm % num1 == 0 && lcm % num2 == 0)
         {
            System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm + ".");
            break;
         }
         ++lcm;
      }
   }
}

3.93
8
POIR 95 points

                                    calculate lcm two numbers in java we can use GCD
public class LCMUsingGCD 
{
   public static void main(String[] args) 
   {
      int num1 = 15, num2 = 25, gcd = 1;
      for(int a = 1; a <= num1 && a <= num2; ++a)
      {
         if(num1 % a == 0 && num2 % a == 0)
         {
            gcd = a;
         }
      }
      int lcm = (num1 * num2) / gcd;
      System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm + ".");
   }
}

3.93 (14 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
find the lcm of two numbers in java lcm and gcd of two numbers in java java program to find lcm and gcd of two numbers java program to find lcm of n numbers lcm of two numbers formula java wap to find lcm of two numbers in java lcm of two numbers in java lcm of 2 numbers with gcd java lcm of 2 numbers java java program to find lcm of two numbers from user find lcm of two numbers in java calculate lcm of two numbers in java Find GCD and LCM of two numbers in java java programme to find lcm of two numbers program to find lcm of two numbers inn java find lcm of 2 numbers in java how to calculate lcm of two numbers in java how to find gcd and lcm of 2 numbers in java java program for lcm of two numbers lcm of two numbers in java shortcut lcm in java of 1 number lcm of two numbers java explanation lcm of two numbers java lcm of three numbers java java program for finding lcm of two numbers java code to find lcm of two numbers find lcm of 3 numbers in java logic to find lcm of two numbers in java find lcm of two numbers find lcm of two numbers inbuilt java find lcm of two numbers java java lcm of 2 numbers lcm of a number in java program to find the greatest of two numbers lcm of two numbers how to find prime numbers between two numbers in java lcm using gcd java hcf and lcm in java using for loop fastest code to find LCM of two numbers Write code to receive two numbers. Then print it, the least common multiple by (prime factorization, modulus, and Euclid's Algorithms) how to find lcm of two numbers lcm java lcm math function in java how to find the lcm of two numbers in java how to find lcm of two numbers in java lcm algorithm java lcm in java lcm using gcd in java find lcm in java how to find lcm of 2 numbers lcm java program java use lcm lcm jaava finding common multiples of two numbers in java lcm java algorithm lcm logic in java lcm in java' find least common multiple java lcm of two numbers in java java least common mltiple java code to calculate lcm of number gcd and lcm of two numbers in java least common multiple java Java program to find LCM of two numbers
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source