冒泡排序

/**
 * 冒泡排序
 *
 * @author lyn
 * @date 2022/3/2 18:40
 */
public class BubbleSortInstance {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sort[] = new int[10];
        System.out.println("输入10个排序的数字");
        for (int i = 0; i < 10; i++) {
            sort[i] = sc.nextInt();
        }
        int temp;
        for (int i = 0; i < sort.length - 1; i++) {
            for (int j = 0; j < sort.length - i - 1; j++) {
                if (sort[j]<sort[j + 1]) {
                    temp = sort[j + 1];
                    sort[j + 1] = sort[j];
                    sort[j] = temp;
                }
            }
        }
        System.out.println("排序后------------------------");
        for (int i : sort) {
            System.out.println(i);
        }

    }
}
posted @ 2022-03-02 18:59  进击的小蔡鸟  阅读(42)  评论(0编辑  收藏  举报