Read integers separated with whitespace into int[] array

前端 未结 10 1897
陌清茗
陌清茗 2020-12-13 19:13

I read line with

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
reader.readLine();

Example input is

10条回答
  •  执念已碎
    2020-12-13 19:19

    Since you don't know the size of input, you can read input as string and then parse the string array to integer array

    String[] arr=reader.readLine().split(" ");
    int[] intarr=new int[arr.length];
    
    for(int i=0;i

提交回复
热议问题