我已经编写了以下代码来添加 java.util 的元素。但我无法从这里继续。
enter code here
import java.io.*;
import java.util.*;
class adder
{
public static void main(String[] args)
{
List<Integer> list = new ArrayList<Integer>();
int b;
System.out.println("Enter the number");
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader bnp = new BufferedReader(inp);
list.add(Integer.parseInt(bnp.readLine()));
for(int i=0;i<list.size();i++)
{
b += list[i];
}
System.out.println("The answer is" + b);
}
}
**OUTPUT**.
add.java:15: array required, but java.util.ArrayList<java.lang.Integer> found
b += list[i];