為什么我輸入score<=60的話結(jié)果會(huì)變成加分八次 61分呢?求解 我知道把等號去掉就可以,但是想不明,請大家賜教
public class HelloWorld {
? ? public static void main(String[] args) {
? ?// 變量保存成績
? ? ? ? int score = 53;?
?// 變量保存加分次數(shù)
? ? ? ? int count = 0;
System.out.println("加分前成績:" +score);
while(score >= 0 && score <= 60){
? ? score ++;
? ? count ++;
}
? //打印輸出加分前成績?
? ? ? ? System.out.println("加分后成績:"+ score);
? ? ? ? System.out.println("共加了"+ count + "次!");
? ? ? ? // 只要成績小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計(jì)加分次數(shù)
? ? ?//打印輸出加分后成績,以及加分次數(shù)
? ? ?
? ? }
}
2015-07-01
當(dāng)score變成60時(shí)不會(huì)退出循環(huán),再進(jìn)行一次自增運(yùn)算,變成61
2015-07-01
score等于60時(shí),也會(huì)執(zhí)行count++,score++,所以當(dāng)然是加到61啦,把count++改成++count試試