根据我输入的大小写,我的切换语句不打印。这是我的代码。在Java中遇到这个问题,这非常令人沮丧。
if (gender == "M"){
switch (activity){
case 1:
newMbmr = (candy1 * .2) + candy1;
System.out.println("A male should eat no more than " +String.format("%.0f", newMbmr) + " candy bars per day to maintain his weight.");
break;
case 2:
newMbmr = (candy1 * .3) + candy1;
System.out.println("A male should eat no more than " +String.format("%.0f", newMbmr) + " candy bars per day to maintain his weight.");
break;
case 3:
newMbmr = (candy1 * .4) + candy1;
System.out.println("A male should eat no more than " +String.format("%.0f", newMbmr) + " candy bars per day to maintain his weight.");
break;
case 4:
newMbmr = (candy1 * .5) + candy1;
System.out.println("A male should eat no more than " +String.format("%.0f", newMbmr) + " candy bars per day to maintain his weight.");
}
}
else if (gender == "F" ){
switch (activity){
case 1:
newWbmr = (candy2 * 1.2) ;
System.out.println("A female should eat no more than " +String.format("%.0f", newWbmr) + " candy bars per day to maintain her weight.");
break;
case 2:
newWbmr = (candy2 * 1.3) ;
System.out.println("A female should eat no more than " +String.format("%.0f", newWbmr) + " candy bars per day to maintain her weight.");
break;
case 3:
newWbmr = (candy2 * 1.4) ;
System.out.println("A female should eat no more than " +String.format("%.0f", newWbmr) + " candy bars per day to maintain her weight.");
break;
case 4:
newWbmr = (candy2 * 1.5) ;
System.out.println("A female should eat no more than " +String.format("%.0f", newWbmr) + " candy bars per day to maintain her weight.");
break;
}
}
它要我输入活动级别,然后我停止执行代码。这很令人困惑,因为它应该根据选择的大小写正确的打印语句。