写一个排序方法,接收一个整型数组,返回排好序的数组。要求不能对原数组有影响

import java.util.Arrays;

public class Test2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] arr = {1,2,3,6,5,4,8,9,8};
//		Arrays.sort(arr);
		System.out.println(Arrays.toString(Arrays.copyOf(arr, arr.length)));
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr.length-i-1; j++) {
				if(arr[j] > arr[j+1]) {
					int temp = arr[j];
					arr[j] = arr[j+1];
					arr[j+1] = temp;
				}
			}
		}
		System.out.println(Arrays.toString(arr));		
	}
}

你可能感兴趣的:(JAVA学习之旅)