
public class GcdAndLcm
{
public static void main(String[] args)
{
int[] result=gAndL(56,48);
System.out.println("最大公约数为:"+result[0]+" 最小公倍数为:"+result[1]);
}
public static int[] gAndL(int x,int y)
{
int[] gl=new int[2];
int m,n,t;
m=x;n=y;
if(x<y)
{
n=x;
m=y;
}
while(m%n!=0)
{
t=n;
n=m%n;
m=t;
}
gl[0]=n;
gl[1]=x*y/n;
return gl;
}
}
最大公约数:8 最小公倍数:336
3139

被折叠的 条评论
为什么被折叠?



