0
    for (int i = 1; i <= value; i++) {
        System.out.print("Player " + i + ", Please Enter your name : ");
        String PlayerName = input.nextLine();
        System.out.print("Please enter a number between 0 and 9 : ");
        int PlayerNumber = input.nextInt();
        System.out.println(PlayerName + " : " + PlayerNumber);
    }

Output : Player 1, Please Enter your name : Please enter a number between 0 and 9 :

If I change input.nextLine to input.next , it will wait for the users first input but he/she won't be able to write their full name.

My question : What can I change so the user can input his full name first and then his number?

OneCricketeer
  • 126,858
  • 14
  • 92
  • 185
Crypto
  • 60
  • 9
  • s it possible to do this from points list: new LatLng(points.get(i).latitude, points.get(i).lontitude)? – Fady Saad May 07 '17 at 18:19
  • 2
    By the way, please don't capitalize your variable names – OneCricketeer May 07 '17 at 18:19
  • I tried the "duplicate question" method but it still doesn't work. If I put a `input.nextLine();` below my `String PlayerName = input.nextLine();` , my output becomes `[blank] : PlayerNumber` – Crypto May 07 '17 at 18:27

1 Answers1

1

Consume the newLine after input.nextInt()

for (int i = 1; i <= value; i++) {
    input.nextLine(); //add this to top
    System.out.print("Player " + i + ", Please Enter your name : ");
    String PlayerName = input.nextLine();
    System.out.print("Please enter a number between 0 and 9 : ");
    int PlayerNumber = input.nextInt();

    System.out.println(PlayerName + " : " + PlayerNumber);
}
dumbPotato21
  • 5,353
  • 5
  • 19
  • 31
  • I'm getting the same output, but if I move the `input.nextLine` below the `String PlayerName = input.nextLine();` , the output will be `[blank] : PlayerNumber` – Crypto May 07 '17 at 18:23
  • 1
    @Crypto check the updated code. Also,are you calling `nextInt` before the for loop ? – dumbPotato21 May 07 '17 at 18:25
  • I'm sorry, I'm very new to Java. I'm still getting the same output with your code. Output : `Player 1, Please Enter your name : Please enter a number between 0 and 9 :` – Crypto May 07 '17 at 18:30
  • 1
    @Crypto try now, I guess your problem should be fixed now. – dumbPotato21 May 07 '17 at 18:31
  • Wow it works! Can you please explain why adding `input.nextLine();` doesn't make the scanner skip to the other one? I can't seem to understand other topics on this – Crypto May 07 '17 at 18:33
  • 1
    @Crypto Glad to help! I suppose you called `nextInt` before the for loop, which caused the problem. Check out the duplicate question for the Explanation. It just consumes the extra newline, which `nextInt` doesn't – dumbPotato21 May 07 '17 at 18:35
  • I kind of understand the concept now. Thank you again for the help man. Now I just have to figure out how to how to add the inputs to an list of some kind so I can fetch them and compare them to the winning number. – Crypto May 07 '17 at 23:40