10-冒泡排序(排序)

public class Test8 {
	public static void main(String[] args) {
		/*
		 * 冒泡排序,经典六行代码
		 */
		int[] arr = { 234, 2, 56, 23, 67, 89, 2 };
		int temp = 0;
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr.length - 1; j++) {
				if (arr[j] > arr[j + 1]) {
					temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
				}
			}
		}
		for (int m : arr) {
			System.out.print(m + " ");
		}
	}

}

你可能感兴趣的:(JAVA)