简单冒泡排序:
import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; public class test { static int a[]={5,2,11,4,31,1,6}; public static void main (String[]age) { System.out.println(Arrays.toString(a)); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a.length-1; j++) { if (a[j]>a[j+1]) { int b=a[j]; a[j]=a[j+1]; a[j+1]=b; } } } System.out.println(Arrays.toString(a)); } }