關(guān)于do while
public?static?void?main(String[]?args)?{
//?TODO?Auto-generated?method?stub
?//?變量保存成績
????????int?score?=?53;?
????????
????????//?變量保存加分次數(shù)
????????int?count?=?0;
????????//打印輸出加分前成績?
????????System.out.println("加分前的成績:"+score);
???????????????
????????
????????//?只要成績小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計加分次數(shù)
//????????if(score<60)
//????????{
//???????? while(score<60){
//???????? count=count+1;
//???????? score=score+1;
//???????? }
//????????}
????????do{
???????? count++;
????????}while(score<60);
????????
????????
//????????for(;score<60;score++){
//???????? count=count+1;
//????????}
????????
????????//打印輸出加分后成績,以及加分次數(shù)
????????System.out.println("加分后的成績:"+score);
????????System.out.println("共加了"+count+"次!");
??????
}for和while都能通
請問我的do while語句存在什么問題,輸出只有一行 ?
加分前的成績:53
2017-08-26
do {}while();沒有問題,但是在do{}while();中沒有執(zhí)行score=score+1;??? 所以程序進入死胡同了,一直執(zhí)行,不能執(zhí)行下面的輸出
2017-08-26
do .....while ?是先執(zhí)行后判斷。。。這樣的話count 計數(shù)會多一次~