我正在尝试从用户那里获取 3 名曲棍球运动员的姓名和球衣号码。然后,我使用我拥有的数据从我创建的名为 HockeyPlayer 的类中创建一个对象。然后我把它放入数组中。第二次迭代不起作用。请帮忙!先感谢您。
ArrayList<HockeyPlayer> array = new ArrayList<HockeyPlayer>();
//For loop to input names
for(int i=0; i < 3; i++)
{
System.out.print("Enter name of Player " + i +":");
startName = keyboard.nextLine();
System.out.print("Enter jersey number of Player " + i +":");
playNum = keyboard.nextInt();
//Make objects and add to array
HockeyPlayer p = new HockeyPlayer(startName, playNum);
array.add(p);
}
keyboard.close();