所以我得到了这个学校作业:
Write a method to take two integer arrays and sort
x[]
intoy[]
using foreach loop.
x[]
的大小为 10,所有元素均使用 Math.random()
初始化,y[]
的大小为 > 10 并用零填充。该方法应将 x[]
数组排序为 y[]
并返回 y[]
。
由于我只剩下 foreach,我无法找到一种方法来引用数组中的其他元素来比较它们。有什么想法吗?
最佳答案
这是我百分百认真的回答。
public static void completelyLegitSort(int[] x,int[] y){
for(int n:x){
System.arraycopy(x, 0, y, 0, x.length);
java.util.Arrays.sort(y);
break;
}
}
关于java - Java中使用foreach对整数数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14991561/