我正在尝试填充一个数组列表,但是我的数组列表始终等于0,而且从未初始化,尽管我在main()中声明了它。
这是我的代码。
static ArrayList<Integer> array = new ArrayList<Integer>(10); //The parenthesis value changes the size of the array.
static Random randomize = new Random(); //This means do not pass 100 elements.
public static void main (String [] args)
{
int tally = 0;
int randInt = 0;
randInt = randomize.nextInt(100); //Now set the random value.
System.out.println(randInt); //Made when randomizing number didn't work.
System.out.println(array.size() + " : Array size");
for (int i = 0; i < array.size(); i++)
{
randInt = randomize.nextInt(100); //Now set the random value.
array.add(randInt);
tally = tally + array.get(i); //add element to the total in the array.
}
//System.out.println(tally);
}
有人可以告诉我发生了什么吗?我感到很愚蠢,我一直使用ArrayList作为我的默认数组,但是我无论如何都解决不了这个问题!