Java使用Scanner实现循环输入
public static void main(String[] args) { Scanner sc = new Scanner(System.in); List<Integer> list = new ArrayList<>(); String input = sc.next(); while (!input.equals("exit")) { list.add(Integer.parseInt(input)); input = sc.next(); } System.out.println(list.toString()); sc.close(); }