public class Sort {
public static void main(String[] args) {
int[] array={4,12,5,9,2,4,2,1,-15,88};
System.out.println("原始数组:");
printArray(array);
sort(array);
System.out.println();
System.out.println("排序结果:");
printArray(array);
}
/**
* 打印数组
* @param array
*/
public static void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]+" ");
}
}
/**
* 冒泡排序
* @param array
*/
public static void sort(int[] array) {
int tmp;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length-1; j++) {
if(array[j]>array[j+1]){
tmp=array[j];
array[j]=array[j+1];
array[j+1]=tmp;
}
}
}
}
}