class ArrayExercise
{
public static void main(String[] args)
{
int[] arr={5,1,6,4,2,8,9};
System.out.println("排序之前");
dayin(arr);
System.out.println("排序之后");
ArraySort(arr);
dayin(arr);
}
public static void ArraySort(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])
{
sawp(arr,x,y);
}
}
}
}
public static void sawp(int[] arr,int a,int b)
{
int sump=arr[a];
arr[a]=arr[b];
arr[b]=sump;
}
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.println(arr[x]+"]");
}
}
} |