public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
String[] s = str.split(" ");
int[] num = new int[s.length];
for (int i = 0; i < s.length; i++) {
num[i] = Integer.parseInt(s[i]);
}
int k=sc.nextInt();
}
}
(1) 当输入用例是 不带空格 的字符串, 用sc.next().
(2) 当输入用例是 带空格 的字符串时,要用 sc.nextLine(). 因为系统默认 空格 会区分两个字符串.
(3) sc.nextInt() 测试用例是整数时.
(4) 多组输入输出时, 一般是 sc.hasNext()…