1. // 对数器
    2. public class DataChecker {
    3. // 创建一个随机数组
    4. static int[] generateRandomArray() {
    5. Random r = new Random();
    6. int[] arr = new int[10];
    7. for (int i = 0; i < arr.length; i++) {
    8. arr[i] = r.nextInt(10);
    9. }
    10. return arr;
    11. }
    12. static void check() {
    13. // 拷贝一份,后续做比较
    14. int[] array = generateRandomArray();
    15. int[] array2 = new int[array.length];
    16. System.arraycopy(array,0,array2,0,array.length);
    17. Arrays.sort(array);
    18. SelectionSort.sort(array2);
    19. boolean same = true;
    20. for (int i = 0; i < array2.length; i++) {
    21. if (array[i] != array2[i]) {
    22. same = false;
    23. }
    24. }
    25. System.out.println(same == true ? "right" : "wrong");
    26. }
    27. public static void main(String[] args) {
    28. check();
    29. }
    30. }