冒泡排序:相邻的两个数值比较大小,互换位置。
public class Bubbling01 { public static void main(String[] args) { int [] nums = {11,22,90,89,78}; for (int i = 0; i < nums.length -1 ; i++) { for (int j = 0; j < nums.length -1 - i; j++) { if(nums[j] < nums[j + 1]) { int tmp = nums[j]; nums[j] =nums[j +1]; nums[j + 1] = tmp; } } } System.out.println(Arrays.toString(nums)); } }