冒泡排序程序

冒泡排序程序,第1张

冒泡排序程序

package com.cos.lession08.demo4;

import java.util.Arrays;


public class MaoPaoDemo {
    public static void main(String[] args) {
        int[] a = { 65, 54, 87, 23, 42, 77, 55, 15, 88, 99 };
        System.out.println(Arrays.toString(a));
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - 1 - i; j++) {
                // 比较 交换 //升序
//                if (a[j]                 if (a[j] > a[j + 1]) {
                    int temp = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(a));

    }
}
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5673026.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存