我无法将扫描的信息放入 Java 中的数组中。
private void initializeFriends()
{
//initialize the size of array:
friends = new Friend[200];
//initialize the first 5 objects(Friends):
friends[0] = new Friend("Rodney Jessep", "rj2013", "Brisbane", "hi!");
friends[1] = new Friend("Jaime Smiths", "abcd5432", "Sydney", "how's going");
friends[2] = new Friend("William Arnold", "william1994", "Brisbane", "boom");
friends[3] = new Friend("James Keating", "qwerty52", "Newcastle", "Hey");
friends[4] = new Friend("Amy Richington", "IAmRichAmy", "Perth", "Yo");
}
运行上述过程后,将运行一个名为的方法addFriends()
,其中扫描仪进入以将数据放入friend
结构中。
将信息扫描到数组中的最佳方法是什么?使用该Scanner in = new Scanner(System.in);
功能是否明智,因为“朋友”中有很多不同的元素:(字符串名称、字符串用户名、字符串城市、字符串消息)?