- class maoPao
- {
- public static void weizhi(int[] arr,int a, int b)
- {
-
- int z=a;
- a=b;
- b=z;
-
- }
- public static void maopao(int[] arr)
- {for(int x=0;x<arr.length;x++)
- {
- for(int y=0;y<arr.length-x-1;y++)
- {
- if(arr[y]>arr[y+1])
- weizhi(arr,arr[y],arr[y+1]);
- }
- }
- }
- public static void main(String[] args)
- {int [] arr={7,1,6,4,2,8,3};
- maopao(arr);
- paixudayin(arr);}
- public static void paixudayin(int[] arr)
- {
- System.out.print("[");
- for(int x=0;x<arr.length;x++)
- { if(x!=arr.length-1)
- System.out.print(arr[x]+",");
- else
- System.out.print(arr[x]+"]");}
- }
- }
复制代码 |
|