1 package test.auto; 2 3 import java.util.Arrays; 4 5 import org.apache.bcel.generic.FieldGenOrMethodGen; 6 7 public class Maopao0807{ 8 9 public static void main(String[] args) { 10 //冒泡,每个相邻进行比较 11 int a[]={ 6, 5, 3, 1, 8, 7, 2, 4 , 0}; 12 for (int i = 0 ;i <a.length-1;i++){ 13 for(int j =0 ; j < a.length-i-1;j++){ 14 if (a[j]<a[j+1]){ 15 int m = a[j]; 16 a[j]=a[j+1]; 17 a[j+1]=m; 18 } 19 } 20 } 21 System.out.println(Arrays.toString(a)+a[1]); 22 23 //选择排序法,一个数依次和后面进行比较 24 int b[]={ 6, 5, 3, 1, 8, 7, 2, 4 , 0}; 25 for (int i =0 ;i<b.length;i++){ 26 for (int j =i;j<b.length;j++){ 27 if (b[i]<b[j]){ 28 int m=b[j]; 29 b[j]=b[i]; 30 b[i]=m; 31 } 32 } 33 34 } 35 System.out.println(Arrays.toString(b)+b[1]); 36 } 37 38 }