Java lcm LCM1(int A, int B)

Here you can find the source of LCM1(int A, int B)

Description

LCM

License

Open Source License

Declaration

public static long LCM1(int A, int B) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static long LCM1(int A, int B) {
        long lowestCommonMultiple = A * B;
        int curNum = 0;
        int indexA = 1;
        int indexB = 1;
        int curA = 1;
        int curB = 1;
        while (curNum < (A * B)) {
            curA = A * indexA;/* www . ja v  a2  s  .co m*/
            curB = B * indexB;
            if (curA < curB) {
                curNum = curA;
                indexA++;
            } else {
                curNum = curB;
                indexB++;
            }

            if ((curNum % A == 0) && (curNum % B == 0)) {
                if (curNum < lowestCommonMultiple) {
                    lowestCommonMultiple = curNum;
                    break;
                }
            }
        }
        return lowestCommonMultiple;
    }
}

Related

  1. lcm(long a, long b)
  2. lcm(long a, long b)
  3. lcm(long u, long v)
  4. lcm(long x, long y)
  5. lcm(long[] a)
  6. lcmPositive(int... args)