java - Java中使用foreach对整数数组进行排序

标签 java arrays sorting foreach int

所以我得到了这个学校作业:

Write a method to take two integer arrays and sort x[] into y[] 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/

相关文章:

java - Afterburner.fx 注入(inject)到非演示者类中可能吗?

java - 查找数组中的对数,其中 A[i] * A[j] > A[i] + A[j]

java - 在 “Integer cannot be converted to E[]”中遇到错误,但在其他地方可以使用?

c - 如何在 C 中对 'æ' 、 'ø' 和 'å' 进行操作

python - 如何在 python 中将单词插入列表?

javascript - PHP 和 html 表,使用 tablesorter javascript

java - BIP39 助记符的种子与测试 vector 不匹配

java - 数据库选择语句的并发问题

Python tkinter : Sorting the contents of an OptionMenu widget

java - 使用泛型实现数组列表,其中列表的最大大小是动态的