- package com.itheima;
 
 - public class Testq 
 
 - {
 
 -         public static void Bianli(int[] arr)
 
 -         {
 
 -                 System.out.print("[");
 
 -                 for(int q=0;q<arr.length;q++)
 
 -                 {
 
 -                         if(q<arr.length-1)
 
 -                         {
 
 -                                 System.out.print(arr[q]+",");
 
 -                         }
 
 -                         else
 
 -                         {
 
 -                                 System.out.print(arr[q]);
 
 -                         }
 
 -                 }
 
 -                 System.out.println("]");
 
 -         }
 
 -         public static void Paixu(int[] arr)
 
 -         {
 
 -         for(int x=0;x<arr.length-1;x++)
 
 -         {
 
 -                 for(int y=0;y<arr.length-1-x;y++)
 
 -                 {
 
 -                         if(arr[y]>arr[y+1])
 
 -                         {
 
 -                                 Zhihuan(arr,y,y+1);
 
 -                         }
 
 -                 }
 
 -         }
 
 -         }
 
 -         public static void Zhihuan(int[] arr,int x,int y)
 
 -         {
 
 -                 arr[x]=arr[x]^arr[y];
 
 -                 arr[y]=arr[x]^arr[y];
 
 -                 arr[x]=arr[x]^arr[y];
 
 -         }
 
 -     public static void main(String[] args) 
 
 -     {
 
 -             int[] arr={3,54,1,25,41,9};
 
 -         Bianli(arr);
 
 -         Paixu(arr);
 
 -         Bianli(arr);
 
 -             
 
 -                     
 
 -     }
 
 - }
 
  复制代码 |