1 package com.array; 2 3 public class Sort_MaoPao { 4 /** 5 * 项目名称:冒泡排序 6 * 项目要求:用JAVA对数组进行排序,并运用冒泡排序算法 7 * 作者:Sevck 8 */ 9 public static void main(String[] args) { 10 int x[] = { 2, 3, 4, 1, 32, 21, 545, 9, 7 }; 11 for (int i = 0; i < x.length; i++) { 12 for (int j = i + 1; j < x.length; j++) { 13 if (x[i] > x[j]) {//修改位置 14 int temp = 0; 15 temp = x[i]; 16 x[i] = x[j]; 17 x[j] = temp; 18 } 19 } 20 System.out.print(" " + x[i] + " "); 21 } 22 } 23 }