-1
使用eclipse編碼時,代碼i ++顯示爲無效代碼。那是什麼意思?爲什麼它是一個死代碼?爲什麼在下面的代碼片段中,「i ++」是死代碼?
public class ScoreCalculator{
public static void main(String[] args) {
int ScoreCard[] = {70,102,198, 60};
String PlayersList[] = {"Mukesh","Suresh","Shardul","Nandan"};
System.out.println(DisplayScore(ScoreCard, PlayersList));
}
public static String DisplayScore(int[] Scores, String[] Players){
for(int i=0; i <= 3; i++){
if(Scores[i]>100 && Scores[i]<=200){
System.out.println("\n******Players who moved to next level******");
return Players[i] + "\n";
}
else
{
System.out.println("\n******Players in Danger Level******");
return Players[i] + "\n";
}
}
return "\n";
}
}
因爲return會在第一次迭代時打破循環 –