java program to find lcm of two numbers

Solutions on MaxInterview for java program to find lcm of two numbers by the best coders in the world

showing results for - "java program to find lcm of two numbers"
Wyatt
11 Aug 2018
1public class LCMOfTwoNumbers
2{
3   public static void main(String[] args)
4   { 
5      int num1 = 85, num2 = 175, lcm;
6      lcm = (num1 > num2) ? num1 : num2;
7      while(true)
8      {
9         if(lcm % num1 == 0 && lcm % num2 == 0)
10         {
11            System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm + ".");
12            break;
13         }
14         ++lcm;
15      }
16   }
17}
Marin
15 May 2020
1calculate lcm two numbers in java we can use GCD
2public class LCMUsingGCD 
3{
4   public static void main(String[] args) 
5   {
6      int num1 = 15, num2 = 25, gcd = 1;
7      for(int a = 1; a <= num1 && a <= num2; ++a)
8      {
9         if(num1 % a == 0 && num2 % a == 0)
10         {
11            gcd = a;
12         }
13      }
14      int lcm = (num1 * num2) / gcd;
15      System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm + ".");
16   }
17}
queries leading to this page
lcm of two numbers formula javahow to calculate lcm of two numbers in javalcm of 2 numbers with gcd javajava program for lcm of two numbershow to find lcm of two numbersjava code to calculate lcm of numberlcm of 2 numbers javaleast common multiple javafind least common multiple javajava program to find gcd and lcm of two numberslcm of multiple numbers in javafind the lcm of two numbers in javajava lcm of 3 numbersjava program to find lcm of two numbers from userjava programme to find lcm of two numberslcm of two numbers in java shortcutfastest code to find lcm of two numberslcm algorithm javalcm in java 27lcm of 3 numbers in javagcd and lcm of two numbers in java lcm of two numbers in javahow to find prime numbers between two numbers in javaprogram to find hcf and lcm of two numbers in javalogic to find lcm of two numbers in javahow to find the lcm of two numbers in javalcm using gcd javalcm java algorithmhow to find gcd and lcm of 2 numbers in javalcm of a number in javaprogram to find the greatest of two numbersfind the lcm of two given integers javalcm of two numbers java explanationlcm java programfind gcd and lcm of two numbers in javajava program for finding lcm of two numbersfind lcm of 2 numbers in javahcf and lcm in java using for looplcm of two numberslcm using gcd in javawrite code to receive two numbers then print it 2c the least common multiple by 28prime factorization 2c modulus 2c and euclid 27s algorithms 29finding common multiples of two numbers in javalcm of two numbers in java using scannerjava program to find lcm of two numbersjava least common mltiplewap to find lcm of two numbers in javajava program to find lcm of 2 numberslcm 26 gcd of two numbers javajava program to find lcm and gcd of two numbershow to find lcm of 2 numberslcm jaavalcm of three numbers javacalculate lcm of two numbers in javalcm and gcd of two numbers in javahow to find hcf and lcm of two numbers in javafind lcm of two numberslcm math function in javaprogram to find lcm of two numbers inn javafind lcm of 3 numbers in javalcm javahow to find lcm and gcd of two numbers javalcm logic in javalcm and hcf of 2 numbers and javajava use lcmfind lcm of two numbers in javajava lcm of 2 numberslcm of two numbers javalcm of two numbers in javalcm in javajava code to find lcm of two numbershow to find lcm of two numbers in javafind lcm of two numbers inbuilt javajava program to find lcm of n numberslcm in java of 1 numberfind lcm of two numbers java find lcm in javajava program to find lcm of two numbers