How to read multiple Integer values from a single line of input in Java?

后端 未结 17 1366
天涯浪人
天涯浪人 2020-11-27 03:16

I am working on a program and I want to allow a user to enter multiple integers when prompted. I have tried to use a scanner but I found that it only stores the first intege

17条回答
  •  -上瘾入骨i
    2020-11-27 03:30

    It's working with this code:

    Scanner input = new Scanner(System.in);
    System.out.println("Enter Name : ");
    String name = input.next().toString();
    System.out.println("Enter Phone # : ");
    String phone = input.next().toString();
    

提交回复
热议问题