题解 | #输入n个整数,输出其中最小的k个#
输入n个整数,输出其中最小的k个
https://www.nowcoder.com/practice/69ef2267aafd4d52b250a272fd27052c
import java.util.Scanner; import java.util.Arrays; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int total = scan.nextInt(); int k = scan.nextInt(); int [] num = new int[total]; for(int i = 0;i < total; i++){ int x = scan.nextInt(); num[i] = x; } Arrays.sort(num); for(int i = 0;i < k; i++){ System.out.print(num[i]+ " "); } } }#算法题解#