美文网首页
m + " 和 " + n + "的最大共约数是:" + res

m + " 和 " + n + "的最大共约数是:" + res

作者: 哈迪斯Java | 来源:发表于2023-05-31 16:09 被阅读0次

public class Computer {
public static int getMaxComm(int m, int n) throws Exception {
if (m <= 0 || n <= 0) {
throw new Exception("传递的参数不是正整数");
}
if (m < n) {
int temp = 0;
temp = m;
m = n;
n = temp;
}
int r = m % n;
while (r != 0) {
m = n;
n = r;
r = m % n;
}
return n;
}

public static void main(String[] args) {
    try {
        int m = 122, n = 0;
        int reslut = getMaxComm(m, n);
        System.out.println(m + " 和 " + n + "的最大共约数是:" + reslut);
    } catch (Exception e) {

        e.printStackTrace();
    }

}

}

相关文章

网友评论

      本文标题:m + " 和 " + n + "的最大共约数是:" + res

      本文链接:https://www.haomeiwen.com/subject/cdvhddtx.html