日期:2014-05-20 浏览次数:20862 次
package com;
public class Test1{
public int gys(int a, int b) {
if(a <= 0 || b <= 0) {
throw new IllegalArgumentException();
}
if(a % b == 0) {
return b;
} else {
return gys(b, a % b);
}
}
public int gbs(int a, int b) {
if(a <= 0 || b <= 0) {
throw new IllegalArgumentException();
}
return (a * b) / gys(a, b);
}
public static void main(String args[]){
Test1 test = new Test1();
System.out.println("最大公约数" + test.gys(4,6) + "最小公倍数" + test.gbs(4,6));
}
}