大神們 看看這個(gè)哪里錯(cuò)了
package?a001; public?class?zgx001?{ public?static?void?main(String[]?args)?{ int?i=53;int?n=0; System.out.println("加分前成績:"+i); do{i++;n++;} while(i>=60); System.out.println("加分后成績:"+i); System.out.println("共加了"+n+"次!"); ?} }
package?a001; public?class?zgx001?{ public?static?void?main(String[]?args)?{ int?i=53;int?n=0; System.out.println("加分前成績:"+i); do{i++;n++;} while(i>=60); System.out.println("加分后成績:"+i); System.out.println("共加了"+n+"次!"); ?} }
2016-10-22
舉報(bào)
2016-10-22
??while(i<=60);
2016-10-31
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? // 變量保存成績
? ? ? ? int score = 61;?
? ? ? ??
? ? ? ? // 變量保存加分次數(shù)
? ? ? ? int count = 0;
? ? ? ? //打印輸出加分前成績?
? ? ? ? ? System.out.println("加分前成績"+score);
? ? ? ?
? ? ? ??
? ? ? ? if(score<60){
? ? ? ? ? ? while(score<60){
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? ? ? score = score+1;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println("一共加分"+count+"次成績合格");
? ? ? ? }else{
? ? ? ? ? ? System.out.println("您的成績已經(jīng)合格不需要加分");
? ? ? ? }// 只要成績小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計(jì)加分次數(shù)
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ? //打印輸出加分后成績,以及加分次數(shù)
? ? ??
? ? }
}
2016-10-22
package?a001;
?
public?class?zgx001?{
????public?static?void?main(String[]?args)?{
????????int?i=53;
????????int?n=0;
????????System.out.println("加分前成績:"+i);
????????do{
????????????i++;
????????????n++;
????????}while(i>=60); ? //主要是錯(cuò)在這里,do-while 語句是先執(zhí)行語句后判斷條件,只有條件成立了,才會繼續(xù)循環(huán),一直到條件不成立了才會結(jié)束循環(huán),再執(zhí)行以下的語句。所以改成?while(i<=60); 就可以了
?????????????
????????System.out.println("加分后成績:"+i);
????????System.out.println("共加了"+n+"次!");
?????}
}
? ?
2016-10-22
while(i<60)
2016-10-22
while內(nèi)容為true則執(zhí)行,你搞反了