java 求最大公约数

public class Main {
public static void main(String[] args) {

System.out.println(gcd(4,8));
}
//辗转相除法
public static int gcd(int x, int y){
if(y == 0)
return x;
else
return gcd(y,x%y);
}
}

猜你喜欢

转载自www.cnblogs.com/sgbe/p/11413331.html