我的代碼哪里出現了問題?
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? // 變量保存成績
? ? ? ? int score = 53;?
? ? ? ??
? ? ? ? // 變量保存加分次數
? ? ? ? int count = 0;
? ? ? ? //打印輸出加分前成績?
? ? ? ? System.out.println("加分前成績"+score);??
? ? ? ?
? ? ? ??
? ? ? ? // 只要成績小于60,就循環執行加分操作,并統計加分次數
? ? ? ? for(;score<60;score++){
? ? ? ? ? ? for(;;count++);
? ? ? ? }
? ? ? ? System.out.println("加分后成績"+score);
? ? ? ? System.out.println("共加了"+count+"次!");
? ? ? ??
? ? ? ? //打印輸出加分后成績,以及加分次數
? ? ??
}
}
2020-07-27
用一個循環就可以了不需要在嵌套一個循環
public class Helloworld{
public static void main(String [] args){
int score=53;
int count=0;
System.out.println("加分前成績"+score);
for(;score<60;score++){
count++;
}
System.out.println("加分后成績"+score);
System.out.println("共加了"+count+"次!")
}
}
2020-07-23
直接count++就行了