`

辗转相除法_最大公约数和最小公倍数

阅读更多
package qinglin.learn.arithmetic;

public class GetMinMultiple
{
	@SuppressWarnings("static-access")
	public static void main(String[] args)
	{
		new GetMinMultiple().getMinMultiple(6, 8);
	}
	public static void getMinMultiple(int a,int b)
	{
		int m=a>b?a:b;
		int n=a<b?a:b;
		int r=1;
		int s=m*n;
		while(n!=0)
		{
			r=m%n;
			m=n;
			n=r;
		}
		System.out.println("the min Multiple is:"+s/m);
		System.out.println("the max divisor is:"+m);
	}
}
分享到:
评论
1 楼 cloud21 2009-10-12  
我可以推荐你一个更好的方法。

public static int getMinMultiple(int x,int y){

while(x!=y){

if(x>y)
{
x=x-y;
}
else{
y=y-x;
}

}

return x;
}

相关推荐

Global site tag (gtag.js) - Google Analytics