-1
int[] a = { 1, 2, 5, 2, 4, 6, 8, 9, 1, 19 };
int[] largestValues = new int[5];
for (int i=0; i < 5; i++) {
System.out.println(largestValues[i]);
}`
int[] a = { 1, 2, 5, 2, 4, 6, 8, 9, 1, 19 };
int[] largestValues = new int[5];
for (int i=0; i < 5; i++) {
System.out.println(largestValues[i]);
}`
您可以使用下面的代碼
對於EG。
public static void main(String args[]) {
int i;
int large[] = new int[5];
int array[] = { 33, 55, 13, 46, 87, 42, 10, 34, 43, 56 };
int max = 0, index;
for (int j = 0; j < 5; j++) {
max = array[0];
index = 0;
for (i = 1; i < array.length; i++) {
if (max < array[i]) {
max = array[i];
index = i;
}
}
large[j] = max;
array[index] = Integer.MIN_VALUE;
System.out.println("Largest " + j + " : " + large[j]);
}
}
「Integer.MIN-VALUE」是做什麼的? –