請(qǐng)問大家關(guān)于這道題這個(gè)哪里不對(duì)。結(jié)果為52 62 4
package mayday;
class yesor{
public static void main(String[] args){
int score = 52;
int count = 0;
System.out.println(score);
package mayday;
class yesor{
public static void main(String[] args){
int score = 52;
int count = 0;
System.out.println("加分前"+score);
while(score<60){count++;score=score+count;
}
System.out.println("加分后"+score);
System.out.println("加分次數(shù)"+count);
}}
2017-11-06
public class HelloWorld {
??? public static void main(String[] args) {
???????
??????? // 變量保存成績
??????? int score = 53;
???????
??????? // 變量保存加分次數(shù)
??????? int count = 0;
??????? //打印輸出加分前成績
???????? System.out.println("加分前成績:"+score) ;
??????
???????
??????? // 只要成績小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計(jì)加分次數(shù)
???????
??????? while (score<60){
??????????? count++;
??????????? score++;
??????? }
????????????
??????? //打印輸出加分后成績,以及加分次數(shù)
????????? System.out.println("加分后成績:"+score);
????????? System.out.println("共加了"+count+"次!");
錯(cuò)誤在于??score=score+count
正確寫為? score++??? //這里表示自加 1
你的寫的代碼有點(diǎn)兒復(fù)雜啦,用一個(gè)簡單的循環(huán)語句(while)就可以了。
2017-09-25
score=score+count;錯(cuò)了 應(yīng)該是 score+=1;或者 score=score+1;
2017-08-31
score=score+count; 錯(cuò)了,應(yīng)該是score++;
2017-08-30
我多復(fù)制了一次,大家從第二個(gè)package mayday;開始看