1 Test1.java 2 3 public class Test1 { 4 5 6 static void method(int [] a){ 7 int b ; 8 for (int i = 0; i < a.length; i++) { 9 10 for (int j = 0; j < a.length-i-1; j++) { 11 12 if (a[j]>a[j+1]) { 13 14 b=a[j+1]; 15 a[j+1]=a[j]; 16 a[j]=b; 17 } 18 } 19 } 20 } 21 }
1 Test2.java 2 3 import java.util.Arrays; 4 5 public class Test2 { 6 7 8 public static void main(String[] args) { 9 int i [] = {5,2,13,4,77,6,412,1}; 10 //Arrays.sort(a); 11 12 13 Test1.method(i); 14 //把数组以字符串形式输出 15 System.out.println(Arrays.toString(i)); 16 } 17 }