• Java经典编程题50道之二十八


    对10个数进行排序。

    public class Example28 {
        public static void main(String[] args) {
            int[] s = { 5, 7, 6, 1, 9, 4, 2, 3, 8 };
            BubbleSort(s);
        }

        public static void BubbleSort(int[] a) {
            System.out.print("原数组为:");
            for (int i : a) {
                System.out.print(i+" ");
            }
            for (int i = 0; i < a.length - 1; i++) {
                for (int j = 0; j < a.length - 1 - i; j++) {
                    if (a[j] > a[j + 1]) {
                        int temp = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
            System.out.print(" 排序后的数组为:");
            for (int i : a) {
                System.out.print(i+" ");
            }
        }
    }

  • 相关阅读:
    NET Core 2.2
    NET Core项目模板
    Eclipse同时显示多个控制台项目的输出
    Java中的序列化
    Java中的泛型
    Java中的集合
    Java中的数据结构
    Java中的包
    Java中的接口
    Java中的封装
  • 原文地址:https://www.cnblogs.com/qubo520/p/6950807.html
Copyright © 2020-2023  润新知