為什么用while語句可以,用do..while語句不行??
public class HelloWorld {
??? public static void main(String[] args) {
???????
??????? // 變量保存成績
??????? int score = 53;
???????
??????? // 變量保存加分次數
??????? int count = 0;
??????? //打印輸出加分前成績
???????? System.out.println("加分前成績:"+score);
??????
???????
??????? // 只要成績小于60,就循環執行加分操作,并統計加分次數
??????? /*while(score<60){
??????????? score=++score;
??????????? count++;
??????? }*/
???????
??????? do{
??????????? score=++score;
???????????? count++;
??????? }while(score>=60)
??????? //打印輸出加分后成績,以及加分次數
????? System.out.println("加分后成績:"+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) {
? ? ? ??
? ? ? ? // 變量保存成績
? ? ? ? int score = 53;?
? ? ? ??
? ? ? ? // 變量保存加分次數
? ? ? ? int count = 0;
?System.out.println("加分前成績:"+score);
? ? ? ? //打印輸出加分前成績?
? ? ? ? ?do{
? ? ? ? ? ? score=++score;
? ? ? ? ? ? ?count++;
? ? ? ? }while(score<60);
? ? ? ?
? ? ? ??
? ? ? ? // 只要成績小于60,就循環執行加分操作,并統計加分次數
? ? ? ? System.out.println("加分后成績:"+score);
? ? ? ? System.out.println("共加了"+count+"次!");
? ? ? ??
2017-05-24
do while是先執行條件在判斷所以條件應該是>=59