為什么用while語(yǔ)句可以,用do..while語(yǔ)句不行??
public class HelloWorld {
??? public static void main(String[] args) {
???????
??????? // 變量保存成績(jī)
??????? int score = 53;
???????
??????? // 變量保存加分次數(shù)
??????? int count = 0;
??????? //打印輸出加分前成績(jī)
???????? System.out.println("加分前成績(jī):"+score);
??????
???????
??????? // 只要成績(jī)小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計(jì)加分次數(shù)
??????? /*while(score<60){
??????????? score=++score;
??????????? count++;
??????? }*/
???????
??????? do{
??????????? score=++score;
???????????? count++;
??????? }while(score>=60)
??????? //打印輸出加分后成績(jī),以及加分次數(shù)
????? System.out.println("加分后成績(jī):"+score);
????? System.out.println("共加了"+count+"次");
??? }
}
2017-05-28
可以
package com.IW;
public class doWhile {
public static void main(String[] arge){
int score=70;
int count=0;
int i=0;
if(score<60){
do{
count++;
i=score+count;
}while(i<60);
}else if(i==0){
i=score;
}
System.out.println(score);
System.out.println(count);
System.out.println(i);
}
}
希望你能滿意!
2017-06-07
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? // 變量保存成績(jī)
? ? ? ? int score = 53;?
? ? ? ??
? ? ? ? // 變量保存加分次數(shù)
? ? ? ? int count = 0;
?System.out.println("加分前成績(jī):"+score);
? ? ? ? //打印輸出加分前成績(jī)?
? ? ? ? ?do{
? ? ? ? ? ? score=++score;
? ? ? ? ? ? ?count++;
? ? ? ? }while(score<60);
? ? ? ?
? ? ? ??
? ? ? ? // 只要成績(jī)小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計(jì)加分次數(shù)
? ? ? ? System.out.println("加分后成績(jī):"+score);
? ? ? ? System.out.println("共加了"+count+"次!");
? ? ? ??
2017-05-24
do while是先執(zhí)行條件在判斷所以條件應(yīng)該是>=59