排序算法

来源:互联网 发布:桌面 知乎 编辑:程序博客网 时间:2024/05/16 13:42

冒泡排序算法:

public static void main(String[] args) {        int [] score = new int[5];        for (int i = 0; i < score.length; i++) {            score[i] = new Random().nextInt(100);            System.out.print(score[i] + " " +i + " " + "\n");        }        for (int i=0; i < score.length; i++) {            for (int j = 0; j < score.length; j++) {                if (score[i] < score[j]) {                    int temp = score[i];                    score[i] = score[j];                    score[j] = temp;                }            }            for (int y = 0; y < score.length; y++) {                System.out.print(score[y] + " ");            }            System.out.print("\n");        }        for (int i = 0; i < score.length; i++) {            System.out.print(score[i] + " ");        }    }