//冒泡排序
class BbubArrayDwmo
{
public static void main(String[] args)
{
//System.out.println("Hello World!");
int arr[]={13,24,2,54,65,46,6};
System.out.println("冒泡前");
getArray(arr);
System.out.println("冒泡后");
arrayFang(arr);
getArray(arr);
}
public static void getArray(int [] arr)
{
System.out.print("[");
for (int x=0;x<arr.length ;x++ )
{
if (x==arr.length-1)
{
System.out.println(arr[x]+"]");
}
else
System.out.print(arr[x]+",");
}
}
public static void arrayFang(int [] arr)
{
for (int x=0;x<arr.length ; x++)
{
for (int y=0;y<arr.length-1 ;y++ )
{
if (arr[y]>arr[y+1])
{
int tem=arr[y];
arr[y]=arr[y+1];
arr[y+1]=tem;
}
}
}
}
}
|
|