/** * 求a和b的最大公约数 * * @param a * @param b */
public void commy(int a, int b) {
int i = 1;
int commyue = 0;
int c = a;
if (c < b)
c = b;
while (i <= c) {
if (a % i == 0 && b % i == 0)
commyue = i;
i++;
}
System.out.println(commyue);
}
/** * a和b的最小公倍数 * * @param a * @param b */
public void commb(int a, int b) {
int c = a;
int commbe = 0;
if (c < b)
c = b;
while (c <= a * b) {
if (c % a == 0 && c % b == 0) {
commbe = c;
break;
}
c++;
}
System.out.println(commbe);
} |