我正在编写一个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();
}
结果: