/** * 冒泡排序 */ import java.util.Scanner; /** * @author zhujin111@jd.com * @version 1.0 * @createDate 2019/06/20 10:57 */ public class BubbleSort { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int array[]=new int[10]; for (int i=0;i<10;i++) array[i]=scanner.nextInt(); bubbleSort(array); for(int i=0;i<10;i++) System.out.print(array[i]+" "); } public static void bubbleSort(int[] array) { int temp = 0; int size = array.length; for(int i = 0 ; i < size; i++) { for(int j =i+1 ;j < size-1 ; j++) { if(array[i] > array[j]) //交换两数位置 { temp = array[i]; array[i] = array[j]; array[j] = temp; } } } } }