Awal
February 12, 2019, 9:04pm
1
Hi,
I am working on a class assignment but I am stuck.
The assignment is
Create an int array called salesFigure that will hold 5 elements.
Use a for loop to print all the elements. (They should all be 0 since no information has been assigned.)
Assign the 5 elements in the array by index location starting at index 0 and through index 4 in this order: (250, 1000, 2500, 4500, 3300)
Print the array using a for loop
Here is what I have.
int[] salesFigures = new int {250, 1000, 2500, 4500, 3300};
numbers[0] = 250;
numbers[1] = 1000;
numbers[2] = 2500;
numbers[3] = 4500;
numbers[4] = 3300;
for (int i = 0; i <salesFigures; i++)
{
System.out.println(salesFigures[i]);
}
I get an error of
expecting DOT, found “salesFigures”
What am I missing?
Thanks
1 Like
Dennis
February 12, 2019, 9:30pm
2
Hi Awal, you have forgot the size method:
for (int i = 0; i <salesFigures.size(); i++)
Keep us up to date!
Awal
February 12, 2019, 10:14pm
3
Thank you Dennis, I made the change but it still is throwing an error. Also where would I know the size based on the directions?
int[] salesFigures = new int{250, 1000, 2500, 4500, 3300}; // THIS IS WHERE THE YELLOW IS
numbers[0] = 250;
numbers[1] = 1000;
numbers[2] = 2500;
numbers[3] = 4500;
numbers[4] = 3300;
for (int i = 0; i <salesFigures.size(); i++)
{
System.out.println(salesFigures[i]);
}
Dennis
February 12, 2019, 10:35pm
4
Hops… I miss:
for (int i = 0; i <salesFigures.length; i++)
Sorry but I’m writing by smartphone and I not tryed it…
Awal
February 12, 2019, 11:44pm
5
Thanks Dennis, I am still getting errors. Sad part is this is only the first half of the assignment. This is going to take me forever.
Chrisir
February 12, 2019, 11:53pm
6
There is a tutorial on arrays
See Website
Since (2) requieres 0 output for all members of the array, shorten your first line before the =
Then for loop with println
Then assign values (you have those 5 lines already)
Then again do the println
Dead easy
Awal
February 13, 2019, 12:35am
7
Dennis, I got it!!! now on to the next part.
Thanks for your help. I may hit you up again if that’s ok.
Awal
February 13, 2019, 12:36am
8
Thanks Chrisir,
I figured it out by watching the a Youtube on Arrays.
Thanks
Chrisir
February 13, 2019, 5:04pm
9
Very good!
Thanks for letting me know…