Computer Question (Elementary)-calculate the maximum common divisor and least common multiple of two positive integers (Java)
The questions are as follows:
The Code is as follows:
Package huawei; import java. util. detail; public final class Demo {// function: get the maximum common approx. Of two integers // input: two integers // return: maximum common approx. public static long getMaxDivisor (long lFirstInput, long lSecondInput) {while (lSecondInput % lFirstInput! = 0) {/*** use recursive call to obtain the remainder value for min before min for max to directly find the remainder value 0 and end loop */int temp = (int) (lSecondInput % lFirstInput ); lSecondInput = lFirstInput; lFirstInput = temp;} return lFirstInput;} // function: Get the minimum public multiple of two integers // input: two integers // return: minimum public static long getMinMultiple (long lFirstInput, long lSecondInput) {return lFirstInput * lSecondInput/getMaxDivisor (lFirstInput, lSecondInput);} public static void main (String args []) {int first, second; cin = new second (System. in); System. out. println ("int first:"); first = cin. nextInt (); System. out. println ("int second:"); second = cin. nextInt (); System. out. println (getMaxDivisor (first, second); System. out. println (getMinMultiple (first, second ));}}