//测试类
class ying3
{
public static void main(String[] args)
{
int[] arr={5,1,6,4,2,8,9};
dayin(arr);
System.out.println();
paixu(arr);
dayin(arr);
}
排序功能
public static void paixu(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;
}
}
}
}
//打印功能
public static void dayin(int[]arr)
{
System.out.print("[");
for (int x=0;x<arr.length ;x++ )
{
if (x<arr.length-1)
System.out.print(arr[x]+",");
else
System.out.print(arr[x]+"]");
}
}
}
|
|