You don't want to declare a variable inside a loop.
You would want to create an array of integers that has a length of 5.
The following line creates a new spot for an array
int[] arrayNameHere;
This line creates an array of integers of length 5 and puts it into the array called "arrayNameHere".
arrayNameHere = new int[5];
Alternatively, you can do the following to keep it in one statement:
int[] arrayNameHere = new int[5];
The for loop would look like this:
for (int i = 0; i < 5; i++)
{
arrayNameHere[i] = 0;
}
This for loop will go through 5 times. Keep in mind that arrays start counting at 0, so the length is 5 and so is the number of objects. However, the counting goes from 0 to 4. The for loop starts at 0 and ends at 4, THE ARRAY DOES NOT START AT 1 AND END AT 5.
It is also common to do the following if the number of objects changes during the program:
for (int i = 0; i < arrayNameHere.length; i++)
{
arrayNameHere[i] = 0;
}
If you want the user to assign the length or number of variables, let the user define the value of the integer x.
arrayNameHere = new int[x];