package ser;
import java.util.*;
public class 最大公约最小公倍数 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("请输入第一个整数:");
int num1 = scan.nextInt();
System.out.print("请输入第二个整数:");
int num2 = scan.nextInt();
System.out.println(maxCommonDivisor2(num1, num2));
System.out.println(minCommonMultiple(num1, num2));
}
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 / maxCommonDivisor2(m, n);
}
}
08-17
3721
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)