java计算最大公因数不正确,如何解决?

请问一下,这段java计算最大公因数输出不正确,请问问题出在哪里?谢谢

img

img

public class xmath {
    public static double smaller(double x, double y) {
        if (x < y) {
            return x;
        } else {
            return y;
        }
    }

    public static int maximum_common_factor(int a, int b) {
        double smaller = smaller(a, b);
        int maximum_common_factor = 1;
        for (int i = 1; i < smaller + 1; i++) {
            if (a % i == 0 & b % i == 0) {
                maximum_common_factor = i;
            }
        }
        return maximum_common_factor;
    }
}
import jpype
jpyJVM = jpype.startJVM(jpype.getDefaultJVMPath())
_xmath = jpype.JClass('xmath')

def maximum_common_factor(a: int, b: int):
    return _xmath.maximum_common_factor(a, b)

if __name__ == '__main__':
    print(maximum_common_factor(2,4))

>>> 输出: 1,应该是2

函数smaller与变量smaller同名?将函数改名为compare_smaller试下。还有if内的与应该是 && 吧,改下看下