class commennum
{
public static void main(String[] args)
{
int number1=4;
int number2=12;
System.out.println("最大公约数是:"+maxcommendiv(number1,number2));
System.out.println("最小公倍数是:"+mincommenmul(number1,number2));
}
public static int maxcommendiv(int a,int b)
{
int r;
while (b!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
public static int mincommenmul(int a,int b)
{
int max,min,i;
max=a>b?a:b;
min=a<b?a:b;
for(i=1;i<min;i++)
{
if (max*i%a==0&&max*i%b==0)
{
return max*i;
}
}
return a*b;
}
} 作者: 好彩哥 时间: 2013-9-6 23:01
很不错哦,,哥们