第一行输入两个整数n和k
第二行输入一个整数数组
输出一个从小到大排序的整数数组
5 2 1 3 5 7 2输出:
1 2
1 import java.util.*; 2 import java.io.*; 3 4 public class Main{ 5 public static void main(String[] args) throws IOException { 6 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 7 String str=""; 8 while((str = br.readLine()) != null){ 9 String[] params = str.split(" "); 10 int n = Integer.parseInt(params[0]); 11 int k = Integer.parseInt(params[1]); 12 13 int[] res = new int[n]; 14 params = br.readLine().split(" "); 15 for (int i = 0; i < params.length; i++) { 16 res[i] = Integer.parseInt(params[i]); 17 } 18 Arrays.sort(res); 19 StringBuilder ans = new StringBuilder(); 20 for(int i =0; i<k; i++) { 21 ans.append(res[i]).append(" "); 22 } 23 System.out.println(ans.toString().trim()); 24 } 25 } 26 }