public static int intDiv(int a, int b) {
if (b != 0) {
return a / b;
} else {
throw new ArithmeticException("Division by zero is not allowed.");
}
}
public static void main(String[] args) {
int a = 500000;
int b = 50;
System.out.println("Result of intDiv(" + a + ", " + b + "): " + intDiv(a, b));
a = 500001;
b = 50;
System.out.println("Result of intDiv(" + a + ", " + b + "): " + intDiv(a, b));
a = 500050;
b = 50;
System.out.println("Result of intDiv(" + a + ", " + b + "): " + intDiv(a, b));
}
输出结果
Result of intDiv(500000, 50): 10000
Result of intDiv(500001, 50): 10000
Result of intDiv(500050, 50): 10001