Java求最大公约数和最小公倍数

//最大公约数
public static int getdivisor(int a, int b)
{
while(a!=b)
{
if(a>b)
a=a-b;
else if(a<b)
b=b-a;
}
return b;
}
  1.0
//最小公倍数
public static int getmultiple(int a,int b)
{
int n=a*b;
while(a!=b)
{

if(a>b)
a=a-b;
else if(a<b)
b=b-a;
}
return n/b;
}

猜你喜欢

转载自cm1993.iteye.com/blog/2283715