解题思路:最大公约数可以使用辗转相除法,https://baike.baidu.com/item/%E8%BE%97%E8%BD%AC%E7%9B%B8%E9%99%A4%E6%B3%95/4625352?fr=aladdin.。最小公倍数:等于两数相乘除以最大公约数
代码:public class Main4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
System.out.println("最大公约数是:"+commonDivisor(a, b));
System.out.println("最小公倍数是:"+a*b/commonDivisor(a, b));
}
public static int commonDivisor(int x,int y){
if(x<y){
int temp=x;
x=y;
y=temp;
}
while(y!=0){
int k=x/y;
x=y;
y=k;
}
return x;
}
}