用 for break報錯
public?static?void?main(String[]?args)?{ ????????int?score?=?53;? ????????int?count?=?0; ????????System.out.println("加分前成績"+score);? ????????for(;score<=60;score++){ ????????????count=count+1; ????????????if(score>=60){ ????????????????break; ????????????????System.out.println(count); ????????????} ????????}?? ????}
System.out.println(count);報錯。。為什么啊
2017-02-09
因為執行了break;以后就會跳出循環,下面那句打印輸出就肯定不會被執行,所以被編譯器認為是多余的。把這句打印輸出和break;上下調換一下位置就行了。
2017-02-09
輸出語句放到for外面
2017-02-09
怎么沒有main語句啊
2017-02-09
把System.out.println(count);放到if外面去
2017-02-09
public?static?void?main(String[]?args)?{
????????int?score?=?53;?
????????int?count?=?0;
????????System.out.println("加分前成績"+score);?
????????for(;score<=60;score++){
????????????count=count+1;
????????????if(score>=60){
????????????????break;
????????????}
????????}??
????????????????System.out.println(count);
????}
?????????把下面一段改成這樣試試