我是想把排序后數(shù)組的前3名成績(jī),賦值給新的數(shù)組??墒遣恢罃?shù)組之間怎么賦值。

yanping_0512
2014-06-06
2 回答
舉報(bào)
0/150
提交
取消
2014-06-07
public static void main(String[] args) { int[] scores = { 89, -23, 64, 91, 119, 52, 73 }; int[] newScores = new int[3]; Arrays.sort(scores); int num = 0; int j=0; for (int i = scores.length - 1; i >= 0; i--) { if (scores[i] < 0 || scores[i] > 100) { continue; } num++; if (num > 3) { break; } newScores[j] = scores[i]; j++; } System.out.println("原數(shù)組:" + Arrays.toString(scores)); System.out.println("新的數(shù)組:" + Arrays.toString(newScores)); }
2014-06-07
回復(fù)中無(wú)法截圖,已添加了新的討論,請(qǐng)看代碼快照