Arrays 如何选择数组中的五个最大值并将它们放入新数组?
如何选择数组中的五个最大值并将它们放入新数组Arrays 如何选择数组中的五个最大值并将它们放入新数组?,arrays,Arrays,如何选择数组中的五个最大值并将它们放入新数组 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[]最大值=新的int[5]; 对于(int i=0;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]);
}
int[]a={1,2,5,2,4,6,8,9,1,19};
int[]最大值=新的int[5];
对于(int i=0;i<5;i++){
System.out.println(最大值[i]);
}
您可以使用以下代码
例如
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]);
}
}
publicstaticvoidmain(字符串参数[]){
int i;
大整数[]=新整数[5];
int数组[]={33,55,13,46,87,42,10,34,43,56};
int max=0,索引;
对于(int j=0;j<5;j++){
max=数组[0];
指数=0;
对于(i=1;i
Integer.MIN-VALUE“做什么?用哪种编程语言?