|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
public class calculator {
public static void main(String[] args) {
}
public static double xiangchen(double num1, double num2) {
double result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 * num2;
System.out.println(result);
return result;
} else {
System.out.println(0);
}
System.out.println(result);
return result;
}
public static double xiangchu(double num1, double num2) {
double result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 + num2;
} else {
System.out.println(0);
System.out.println(result);
double result1 = result;
return result1;
}
public static double xiangjian(double num1,double num2){
double result2 = 0;
if (num1 != 0 && num2 != 0) {
result = num1 - num2;
} else {
System.out.println(0);
System.out.println(result);
return result2;
}
public static double xiangchu(double num1, double num2){
result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 / num2;
} else {
System.out.println(0);
System.out.println(result);
return result;
}
}
}
}
}
好久没玩论坛了,问问大家的代码格式是怎么弄出来的 , 我这个方法 为啥前面两个if不报错 后面两个报错 编译器时idea
代码格式在 <> 这个按钮处,或者自己输入 [code ] [/ code] 这个标签
你这里代码错误是因为你定义了两个 xiangchu,你第一个 xiangchu 函数应该是 xiangjia 吧
另外你代码很乱,最后括号啥的也是非常的混乱,我帮你改过来了,删掉了无用部分的代码
参考代码:
public class calculator {
public static void main(String[] args) {
System.out.println(xiangchen(10, 10));
System.out.println(xiangjia(10, 10));
System.out.println(xiangjian(10, 10));
System.out.println(xiangchu(10, 10));
}
public static double xiangchen(double num1, double num2) {
double result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 * num2;
return result;
}
return result;
}
public static double xiangjia(double num1, double num2) {
double result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 + num2;
}
return result;
}
public static double xiangjian(double num1, double num2) {
double result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 - num2;
}
return result;
}
public static double xiangchu(double num1, double num2) {
double result = 0;
if (num1 != 0 && num2 != 0) {
result = num1 / num2;
}
return result;
}
}
|
|