The greatest common divisor and the common multiple
 No. 110
               
Finding the greatest common divisor of two integer values
| 
                            Q:  | 
                        
                            We recall the section called “Example: A class representing fractions”. So far no one
                                            demanded cancelling fractions. Yet calling  Cancelling fractions requires implementing e.g. the Euclidean algorithm in order to find the greatest common divisor (GCD) of two non-zero integer values. Read the above link and implement a class method
                                            getGcd(long, long) inside a class
                                             public static long getGcd(long a, long b) ❶ {
  // Following http://www.math.rutgers.edu/~greenfie/gs2004/euclid.html
  return ??; //TODO
}With respect to fractions one or both parameters  
 Based on  TipFollow the test driven approach: Provide dummy methods
                                                 and write tests prior to implementation of
                                                   | 
                     
| 
                            A:  | 
                        
 Implementing  public static long getGcd(long a, long b) { // Following http://www.math.rutgers.edu/~greenfie/gs2004/euclid.html if (a < b) { // Swap the values of a and b final long tmp = a; a = b; b = tmp; } while (0 != b) { final long r = a % b; a = b; b = r; } return a; } Knowing the the gcd of two values a and b the common multiple may be obtained by . Thus we have: public static long getLeastCommonMultiple(long a, long b) { final long gcd = getGcd(a, b); if (1 == gcd) { return a * b; } else { return (a / gcd) * b; } }  | 
                     
