本帖最后由 傲鸽 于 2013-6-22 23:11 编辑
class Demo
{
public static void main(String[] args)
{
int[] arr1={2,5,8,1,4,3};
System.out.println(print(arr1));
bubbleSort(arr1);
System.out.println(print(arr1));
}
public static void bubbleSort(int[] arr){
for (int i=0;i<arr.length-1 ; i++){
for (int j=0;j<arr.length-1-i ;j++ ){
if(arr[j]>arr[j+1]){
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
public static String print(int[] arr){
String str="[";
int x=0;
while (x!=arr.length-1){
str=str+arr[x]+",";
}
str=str+arr[x]+"]";
return str;
}
}
|