How to read multiple integer values from one line in Java using BufferedReader object?

前端 未结 9 2240
萌比男神i
萌比男神i 2021-02-06 15:39

I am using BufferedReader class to read inputs in my Java program. I want to read inputs from a user who can enter multiple integer data in single line with space. I want to rea

9条回答
  •  不知归路
    2021-02-06 16:22

    If you want to read integers and you didn't know number of integers

    String[] integersInString = br.readLine().split(" ");
    int a[] = new int[integersInString.length];
    for (int i = 0; i < integersInString.length; i++) {
        a[i] = Integer.parseInt(integersInString[i]);
    }
    

提交回复
热议问题