题目描述:
输入n个整数,输出其中最小的k个。
输入描述:
1 输入两个整数
2 输入一个整数数组
输出描述:
输出一个整数数组
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext())
{
int n = scanner.nextInt();
int k = scanner.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = scanner.nextInt();
}
Arrays.sort(arr);
int i = 0;
for (; i < k - 1; i++)
System.out.print(arr[i] + " ");
System.out.println(arr[i]);
}
}
}