第一题
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
while (sc.hasNextInt()) {
    list.add(sc.nextInt());
}
第二题
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
string s = sc.nextLine();
int k = sc.nextInt();
String[] numString = in.nextLine().split(" ");
for (String t:numString) {
    list.add(Integer.parseInt(t));
}