Java 如何让我的nextLine()等待用户';谁的输入? for(int i=1;i

Java 如何让我的nextLine()等待用户';谁的输入? for(int i=1;i,java,java.util.scanner,Java,Java.util.scanner,在input.nextInt()之后使用换行符 for(int i=1;i从点列表:new LatLng(points.get(i).latitude,points.get(i).lontitude)可以这样做吗?顺便说一句,请不要将变量名称大写。我尝试了“复制问题”方法,但仍然不起作用。如果我在字符串PlayerName=input.nextLine()下面放一个;,我的输出变为[空白]:PlayerNumber我得到了相同的输出,但是如果我将输入.nextLine移动到字符串PlayerNa

input.nextInt()之后使用换行符


for(int i=1;i从点列表:new LatLng(points.get(i).latitude,points.get(i).lontitude)可以这样做吗?顺便说一句,请不要将变量名称大写。我尝试了“复制问题”方法,但仍然不起作用。如果我在
字符串PlayerName=input.nextLine()下面放一个
,我的输出变为
[空白]:PlayerNumber
我得到了相同的输出,但是如果我将
输入.nextLine
移动到
字符串PlayerName=input.nextLine();
,输出将变为
[空白]:PlayerNumber
@Crypto检查更新的代码。另外,在for循环之前您是否正在调用
nextInt
?对不起,我对Java非常陌生。我仍然得到与您的代码相同的输出。输出:
Player 1,请输入您的姓名:请输入一个介于0和9之间的数字:
@Crypto现在再试一次,我想您的问题应该是fixed now.@Crypto很乐意帮忙!我想你在for循环之前调用了
nextInt
,这导致了问题。请查看重复问题的解释。它只消耗了额外的换行符,而
nextInt
没有
    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);
    }
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);
}