直接上代码- class Max
- {
- public static void main(String[] args)
- {
- int [] arr = {18,27,6,81,101,15,2};//7
- System.out.print("冒泡前:");
- for (int a=0;a<arr.length ;a++ )
- {
- System.out.print(" "+arr[a]);
- }
- System.out.println();
- getMax(arr);
- }
- public static void getMax(int [] a)
- {
- int temp=0;
- for (int b=0;b<a.length ;b++ )
- {
- for (int c=b+1;c<a.length;c++ )
- {
- if (a[b]>a[c])
- {
- temp=a[b];
- a[b]=a[c];
- a[c]=temp;
- }
- }
- }
- System.out.print("冒泡后:");
- for (int b=0;b<a.length;b++ )
- {
- System.out.print(" "+a[b]);
- }
- }
- }
复制代码
|
|