Java使用hasNext()输入不定长数组

1 Scanner scan = new Scanner(System.in);
2 String s = scan.nextLine();
3 Scanner sc = new Scanner(s);
4 List<Integer> input = new ArrayList<>();
5 while(sc.hasNext()){
6        input.add(sc.nextInt());
7 }

 

 
posted @ 2020-10-26 09:31  dretrtg  阅读(537)  评论(0)    收藏  举报