标签:
链接里面写了两种
http://blog.csdn.net/songylwq/article/details/7714622
第三种:
public class GcdLcm{
public static void main(String []args){
if(args.length<2){
System.out.println("Please input two number...");
System.exit(0);
}
int m=Integer.parseInt(args[0]);
int n=Integer.parseInt(args[1]);
if(m<n){
int temp=m;
m=n;
n=temp;
}
int t1=m,t2=n;
int r;
while((r=t1%t2)!=0){
t1=t2;
t2=r;
}
System.out.println("=========="+m+"和"+n+"=========");
System.out.println("最大公约数:"+t2);
System.out.println("最小公倍数:"+m*n/t2);
}
}
标签:
原文地址:http://www.cnblogs.com/tengke/p/5568210.html