I assume Answer as an Integer data type, so in this case you can easily use Scanner class for adding the multiple elements (say, 50).
private static final Scanner obj = new Scanner(System.in);
private static ArrayList<Integer> arrayList = new ArrayList<Integer>(50);
public static void main(String...S) {
for (int i=0; i<50; i++) {
/* Using Scanner class object to take input. */
arrayList.add(obj.nextInt());
}
/* You can also check the elements of your ArrayList. */
for (int i=0; i<50; i++) {
/* Using get function for fetching the value present at index 'i'. */
System.out.print(arrayList.get(i) + " ");
}
}
This is a simple and easy method for adding multiple values in an ArrayList using a for loop.
As in the above code, I presume the Answer as Integer. It could be String, Double, Long, etc. So, in that case, you can use next(), nextDouble(), and nextLong(), respectively.