int [] nums = {5,4,8,6,2,1}; int tmp = 0; //采用冒泡排序 升序 for (int j = 0; j < nums.length -1; j++) { for (int i = 0; i < nums.length -j-1; i++) { if(nums[i] > nums[i+1]){ tmp = nums[i]; nums[i] = nums[i+1]; nums[i+1] = tmp; } } } for (int num:nums ) { System.out.print(num+ "\t"); }