在不考虑时间的情况下直接使用Arrays.sort来排序
常规使用默认升序,降序需要进行调整
import java.io.*;
import java.util.*;
public class Main {
static Scanner tab = new Scanner(System.in);
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static int N = 110;
static Integer a[] = new Integer [7]; // 降序sort必须使用Integer数组
static boolean st[] = new boolean [7];
// 定义一个降序Comparator
static class Cmp implements Comparator<Integer>{
@Override
public int compare(Integer a, Integer b) {
// TODO Auto-generated method stub
return a > b ? -1 : 1;
}
}
public static void main(String[] args) throws IOException {
for(int i = 0; i < 7; i++) {
a[i] = tab.nextInt();
}
// Cmp作为参数输入
Arrays.sort(a, new Cmp());
for(int i : a) {
System.out.print(i + " ");
}
}
}