- //数组的冒泡排序
- public class DemoArrayTest02 {
- public static void main(String[] args) {
- int[] arr = new int[] { 64, 12, 74, 23, 98, 1, 45, 87 };
- int temp = arr[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;
- }
- }
- }
- System.out.print(Arrays.toString(arr));
- }
- }
复制代码 |