菜鸟提问 高手们帮帮忙

2025-12-18 04:23:17
推荐回答(1个)
回答1:

原因很简单
是因为你的类方法写到main方法里面了
public static void main(String[]args) {
Test t = new Test();
t.m(0);

void m(int i) throws ArithmeticException {
if(i == 0)
new throw ArithmeticException("被除数为0");
}
}
应该将m这个方法写在main方法外面
现给你改成
public class Test {
public static void main(String[]args) {
Test t = new Test();
t.m(0);
}
void m(int i) throws ArithmeticException {
if(i == 0)
new throw ArithmeticException("被除数为0");
}

}