I was trying to take an unknown number of integers from the user (until the user enters 0), and count the number of occurrences of each of the integers entered. I figured, to count after I'm done taking the integers, I'd have to store them in an array. And I did some research and realized that the only way to create an Array with an unspecified length, ArrayList is the only way. But my this part of the code is showing error:
import java.util.Scanner;
import java.util.ArrayList;
public class IntegersOccurence {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.print("Enter the integers between 1 and 100: ");
ArrayList list = new ArrayList();
System.out.println(list.get(0));
//eclipse is showing an error in the line right below
while (list.get(list.size() - 1) != 0) {
list.add(input.nextInt());
}
}
}