public class Calculator {
Calculator() {
}
public int add(int a, int b) {
return a + b;
}
public int subtract(int a, int b) {
return a - b;
}
public int multiply(int a, int b) {
return a * b;
}
public int divide(int a, int b) {
return a/b;
if(b == 0) {
System.out.println("Error! Dividing by zero is not allowed.");
return 0;
else {
return a/b;
}
}
}
public int modulo(int a, int b) {
if(b == 0) {
System.out.println("Error! Dividing by zero is not allowed.");
return 0;
else {
return a % b;
}
}
}
public static void main(String[] args) {
Calculator myCalculator = new Calculator();
System.out.println(myCalculator.add(5, 7));
System.out.println(myCalculator.subtract(12, 34));
}
}
出现的错误:
Calculator.java:23: 错误:'else' 没有 'if' else {
Calculator.java:33: 错误:'else' 没有 'if' else {
仍然是初学者,所以如果你想添加一些技巧,我会很感激。
千巷猫影
相关分类