import java.util.Scanner; public class BubbleSort { public static int[] BubbleSort(int[] a){ int temp; for(int j= a.length-1;j>0;j--){ for(int i = 0; i < a.length-1-j;i++){ if (a[i+1]<a[i]){ temp = a[i+1]; a[i+1]=a[i]; a[i]= temp; } } } return a; } public static void main(String[] args){ Scanner input= new Scanner(System.in); System.out.println("please enter in ..."); int [] array = new int [10]; for(int i = 0;i<array.length-1;i++){ array[i]=input.nextInt(); } int []arr2 =new int[10]; int[] a=BubbleSort(array); for(int i = 0;i<array.length-1;i++){ System.out.println(array[i]); } } }
JustWannaHugU
相关分类