Java冒泡排序

2018-11-28 14:25:26  卢浮宫  版权声明:本文为站长原创文章,转载请写明出处



package com.xa;
public class BubbleSort {
public static void main(String[] args) {
int score[] = { 1, 3, 6, 4, 89, 66, 56, 9 };
for (int i = 0; i < score.length - 1; i++) {
for (int j = 0; j < score.length - i - 1; j++) {
if (score[j] > score[j + 1]) {
int temp = score[j];
score[j] = score[j + 1];
score[j + 1] = temp;
}
}
}
System.out.println("最终的排序是:");
for (int x = 0; x < score.length; x++) {
System.out.print(score[x] + " ");
}
}
}

    最终的排序是:
    1 3 4 6 9 56 66 89




更多精彩请关注guangmuhua.com


最新评论: