java 实例 冒泡排序
2017-03-20 10:26 backyyan 阅读(184) 评论(0) 编辑 收藏 举报public class maopaopaixu { public static void main(String[] args) { int score[] = { 5, 6, 4, 8, 7, 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.print("第" + (i + 1) + "次排序结果:"); for (int a = 0; a < score.length; a++) { System.out.print(score[a] + "\t"); } System.out.println(""); } System.out.print("最终排序结果:"); for (int a = 0; a < score.length; a++) { System.out.print(score[a] + "\t"); } } }