java if 语句 求大神指点
classTest03{main(){intcups=3;doubleprice=5.0;doublepay=0.0;if(cups>0){pay=price;if(cu...
class Test03{
main(){
int cups = 3;
double price = 5.0;
double pay = 0.0;
if(cups>0){
pay = price;
if(cups>1){
if(cups%2==0){
pay = (5+2.5)*(cups/2);
}else{
pay = (5+2.5)*(cups/2)+price;
}
}
}
else{
System.out.println("不卖!");
int cups1 =5;
double a1 = 5.0;
double pay1 = 0.0;
if(cups1>=1){
if(cups1%2==0){
pay1 = cups1/2*(a1+a1/2);
System.out.println(pay1);
}else if(cups1%2!=0){
pay1 = a1+(a1+a1/2)*((cups1-1)/2);
System.out.println(pay1);
}
这两个代码输出的结果都是一样的 如果cup%2!=0的时候 pay = (5+2.5)*(cups/2)+price; pay1 = a1+(a1+a1/2)*((cups1-1)/2);这两句话 为什么 没区别 不是应该cup-1再除以2吗? 展开
main(){
int cups = 3;
double price = 5.0;
double pay = 0.0;
if(cups>0){
pay = price;
if(cups>1){
if(cups%2==0){
pay = (5+2.5)*(cups/2);
}else{
pay = (5+2.5)*(cups/2)+price;
}
}
}
else{
System.out.println("不卖!");
int cups1 =5;
double a1 = 5.0;
double pay1 = 0.0;
if(cups1>=1){
if(cups1%2==0){
pay1 = cups1/2*(a1+a1/2);
System.out.println(pay1);
}else if(cups1%2!=0){
pay1 = a1+(a1+a1/2)*((cups1-1)/2);
System.out.println(pay1);
}
这两个代码输出的结果都是一样的 如果cup%2!=0的时候 pay = (5+2.5)*(cups/2)+price; pay1 = a1+(a1+a1/2)*((cups1-1)/2);这两句话 为什么 没区别 不是应该cup-1再除以2吗? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询