请问我写的这个代码错在哪里了呢?想不通啊
package excise02;
public class test12 {
public static void main(String[] args) {
int score=53;
int count=0;
System.out.println("加分前的分数为:"+score);
for(int i=53;i<60;i++){
score=i;
count+=1;
}
System.out.println("加分后的分数为:"+score);
System.out.println("共加了"+count+"次!");
}
}输出结果为
加分前的分数为:53
加分后的分数为:59
共加了7次!
如果把代码改成
package excise02;
public class test1202 {
public static void main(String[] args) {
int score=53;
int count=0;
System.out.println("加分前的分数为:"+score);
for(score=53;score<60;score++){
count+=1;
}
System.out.println("加分后的分数为:"+score);
System.out.println("共加了"+count);
}
}这样就没有错了
我指定一个整型变量i,放到循环条件中去,再用i给score赋值,虽然多此一举,但是感觉没有错啊,想不出来为什么会错.