java 小代码错误找不出来,请帮忙看看

来源:百度知道 编辑:UC知道 时间:2024/05/22 05:18:33
public class Test {
public double division(double i) throws ArithmeticException {
if(i == 0) {
throw new ArithmeticException
}else {
return 100/i;
}
}
public static void main(String[] args) {
Test t = new Test();
t.division(2);
}
}

C:\workspace\08.2.2\Test>javac Test.java
Test.java:5: 需要为 '(' 或 '['
}else {
^
1 错误

public class Test {
public double division(double i) throws ArithmeticException {
if(i == 0) {
throw new ArithmeticException
}else {
return 100/i;
}
}
public static void main(String[] args) {
Test t = new Test();
t.division(2);
}

- -!
一点小错误:
改正后:
public class Test {
public double division(double i) throws ArithmeticException {
if (i == 0) {
throw new ArithmeticException();
} else {
return 100 / i;
}
}

public static void main(String[] args) {
Test t = new Test();
t.division(2);
}
}