随笔 - 78  文章 - 25  trackbacks - 0
<2009年11月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿

随笔分类(75)

随笔档案(78)

相册

实用Links

我的Links

搜索

  •  

积分与排名

  • 积分 - 111810
  • 排名 - 519

最新评论

阅读排行榜

评论排行榜

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
posted on 2009-11-23 23:10 期待明天 阅读(316) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: