可以把下面的代码中的数组用Arraylist代替而不影响运行的结果吗,怎么改,我试了半天没有弄出来,请指教了!
(一共创建了两个类,只贴出主方法的,另一个类是属性和构造方法的类)。
public static void main(String[] args) {
Game game[] = new Game[50];
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int i=0;
try {
for ( i = 0; i < game.length; i++) {
System.out.println("请输入第"+(i+1)+"个游戏的信息:");
System.out.println("输入游戏名称:");
String name = bf.readLine();
System.out.println("输入游戏等级:");
int level=0;
try {
 level =Integer.parseInt(bf.readLine());
}catch(NumberFormatException nfe) {
System.out.println("输入有误!");
}
game[i] = new Game(name,level);
System.out.println("是否继续录入学员信息?(Y/N)");
String answer = bf.readLine();
if("y".equals(answer) == false) {
break;
}
}
System.out.println("所有游戏的信息如下:");
for (int j = 0; j < i+1; j++) {
System.out.println(game[j]);
}
}catch(IOException e) {
e.printStackTrace();
}
}