我正在尝试从 ArrayList 中的用户获取值,我可以获取 ArrayList 大小的输入,但是,当我尝试添加元素时,程序正在终止。这是我的代码import java.io.*;import java.util.*;public class ArrayDemo{public static void main(String...args)throws IOException{ try { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the size of array:"); int n=Integer.parseInt(b.readLine()); ArrayList<Integer> a=new ArrayList<Integer>(n); System.out.println("Enter the elements"); for(int i=1;i<=n;i++) { a.add(b.read()); } System.out.println(a); }catch(Exception e) { System.err.println(""); }}}
添加回答
举报
0/150
提交
取消