<pre name="code" class="java">class maopao { public static void main(String[] args) { int[] arr ={1,3,4,7,5,9,8}; int[] arr1=Fun(arr); for (int m=0;m<arr.length ;m++ ) { if (m<arr.length-1) { System.out.print(arr1[m]+","); } else { System.out.println(arr1[m]); } } System.out.println("Hello World!"); } static int[] Fun(int[] m) { //外循环; for (int i=1;i<m.length ;i++ ) { for (int j=0;j<m.length-i ;j++ ) { if (m[j]>m[j+1]) { //交换方法一: /*int temp; temp = m[j+1]; m[j+1] = m[j]; m[j] = temp; */ //交换方式二: int temp; temp = m[j]^m[j+1]; m[j]=temp^m[j]; m[j+1]=temp^m[j+1]; //m[j]=m[j]^m[j]^m[j+1]; //m[j+1]=m[j+1]^m[j+1]^m[j]; } } } return m; } }
在学习的过程中有许多需要注意的地方。