第1个回答 推荐于2016-03-18
public class Du21 {
public static void main(String[] args) {
int score[] = {1,2,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
int[] tempAry = new int[score.length];
int nonZeroCount = 0;
for(int i = 0, j= 0;i < score.length; i++){
if(score[i] != 0){
tempAry[j++] = score[i];
nonZeroCount++;
}
}
int newScore[] = new int[nonZeroCount];
for(int i = 0; i < newScore.length; i++){
newScore[i] = tempAry[i];
System.out.print(newScore[i] + ", ");
}
}
}
-----------testing
1, 2, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5,本回答被提问者采纳