public class Test {
/**递归求最大公约数*/
public static int maxCommonDivisor(int m, int n) {
if (m < n) {
int temp = m;
m = n;
n = temp;
}
if (m % n == 0) {
return n;
} else {
return maxCommonDivisor(n, m % n);
}
}
/**循环求最大公约数*/
public static int maxCommonDivisor2(int m, int n) {
if (m < n) {
int temp = m;
m = n;
n = temp;
}
while (m % n != 0) {
int temp = m % n;
m = n;
n = temp;
}
return n;
}
/**最小公倍数*/
public static int minCommonMultiple(int m, int n) {
return m * n / maxCommonDivisor(m, n);
}
public static void main(String[] args) {
System.out.println(Test.maxCommonDivisor(24, 60));
System.out.println(Test.minCommonMultiple(3, 21));
}
}