附上一段代码,会直观一点:
import java.util.Arrays;
class SortDemo
{
public static void main(String[] args)
{
int[] vec={0,15,-14,45,20,70};
Arrays.sort(vec);
System.out.println("升序排列:");
for (int i=0;i<vec.length ;i++ )
{
System.out.print(vec[i]+" ");
}
System.out.println("/n");
System.out.println("降序排列:");
for (int i=vec.length-1;i>=0 ;i-- )
{
System.out.print(vec[i]+" ");
}
}
} |