题解 | #输入整型数组和排序标识,对其元素按照升序或降序进行排序#
输入整型数组和排序标识,对其元素按照升序或降序进行排序
http://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
简单的利用arrays.sort进行升降排序
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
Integer arr[] = new Integer[num];
for(int i = 0;i<arr.length;i++){
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
int chos = sc.nextInt();
if(chos == 0){
for(int i = 0;i<arr.length;i++){
System.out.print(arr[i] + " ");
}
}
else if(chos == 1){
for(int i = arr.length - 1;i >= 0;i--){
System.out.print(arr[i] + " ");
}
}
}
}