public static double findLCM (int num1, int num2) {
for (int i = 1; i <= num2; i++) {
double mult = big * i;
if (mult % small == 0) {
return mult;
}
}
throw new Error("Error");
}
众所周知,没有 LCM 是不可能的。请不要向我建议代码的解决方法,例如从 for 循环中断后返回变量等。此代码是定制的,用于理解要抛出的异常。
最佳答案
最接近的可能是 IllegalArgumentException :
Thrown to indicate that a method has been passed an illegal or inappropriate argument.
关于java - 对于不可能的情况应该抛出什么错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29777949/