Java:for循环无法正确收集数据

时间:2020-05-30 22:55:17

标签: java for-loop

我正在编写一个for循环,以跟踪团队中的球员。首先,循环会询问有多少玩家,然后您添加信息。

第一次迭代完全跳过了玩家名称,我不知道为什么在其余的迭代中正确收集玩家名称的原因。

代码:

System.out.print("Enter the number of players on your team: ");
    int n = s.nextInt();

    for(int i = 1; i <= n; i++) {
        System.out.println("Player's name: ");
        name = s.nextLine();
        System.out.println("Player's position: ");
        position = s.nextLine();
        System.out.println("Player's jersey number: ");
        number = s.nextLine();
    }

结果:

Results of for loop

0 个答案:

没有答案
相关问题