直接贴代码 辗转相除法
public class Ab {
public static void main(String[] args) {
int gcd = gcd(49, 91);
System.out.println("2个数最大公约数:"+gcd);
int gcd2 = gcd(26460, 12375);
System.out.println("2个数最大公约数:"+gcd2);
int gcd3 = gcd(gcd(45, 105), 30);
System.out.println("3个数最大公约数:"+gcd3);
int gcd1 = gcd2(49, 91);
System.out.println("2个数最大公约数:"+gcd);
}
public static int gcd(int a,int b){
while (b!=0){
int temp=a%b;
a=b;
b=temp;
}
return a;
}
public static int gcd2(int a,int b){
if (b!=0){
int temp=a%b;
a=b;
b=temp;
gcd2(a,b);
}
return a;
}
}