public static void main(String[] args) {
// TODO Auto-generated method stub
int [] array={12,4,2,7,5,9};
method(array);
}
//冒泡排序
public static void method(int [] array){
for(int i=0;i<array.length;i++){
for(int j=0;j<array.length-1-i;j++){
if(array[j]>array[j+1]){
//将数值大的元素往后放
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
method1(array);
}
//数组的遍历
public static void method1(int [] array){
for(int i=0;i<array.length;i++){
System.out.print(array[i]+" ");
}
} |
|