You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
620 B
32 lines
620 B
package jisuanji;
|
|
public class Calculator {
|
|
// 加法
|
|
public double add(double a, double b) {
|
|
return a + b;
|
|
}
|
|
|
|
// 减法
|
|
public double subtract(double a, double b) {
|
|
return a - b;
|
|
}
|
|
|
|
// 乘法
|
|
public double multiply(double a, double b) {
|
|
return a * b;
|
|
}
|
|
|
|
// 除法
|
|
public double divide(double a, double b) {
|
|
if (b != 0) {
|
|
return a / b;
|
|
} else {
|
|
throw new IllegalArgumentException("除数不能为零");
|
|
}
|
|
}
|
|
|
|
// 取余
|
|
public double modulus(double a, double b) {
|
|
return a % b;
|
|
}
|
|
}
|