class SortArray
{
public static void main(String[] args)
{
int[] arr = new int[]{1,6,3,34,3,54,7,66,19};
System.out.print("sort the array:");
printArr(arr);
System.out.print("sort result is:");
printArr(sortArr(arr));
}//end of method main
//对一个数组按照从小到大的顺序进行排序
public static int[] sortArr(int[] arr)
{
for (int x = 0; x<arr.length - 1; x++)
{
for (int y = x + 1; y<arr.length; y++)
{
if (arr[x]>arr[y])
{
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
}
}
return arr;
}//end of method sortArr
//打印一个数组
public static void printArr(int[] arr)
{
for (int x = 0; x<arr.length; x++ )
{
if (x == arr.length - 1)
{
System.out.println(arr[x]);
break;
}
System.out.print(arr[x] + ",");
}
}//end of method printArr
}//end of class SortArray