28.冒泡排序
时间:2016-05-27 23:43:35
收藏:0
阅读:352
/* * 冒泡排序 * */ public class SortNum { public static void main(String[] args) { int[] scores={16,25,9,90,23}; for (int i = 0; i < scores.length -1 ; i++) { for (int j = 0; j < scores.length -1 - i ; j++) { if (scores[j] > scores[j + 1]) { // 交换元素 int temp = scores[j]; scores[j] = scores[j + 1]; scores[j + 1] = temp; } } } System.out.println("冒泡排序后:"); for(int score:scores){ System.out.print(score+"\t"); } } }
原文:http://www.cnblogs.com/xiaotaoxu/p/5536339.html
评论(0)