# Creating an Array

**URL:** <https://discourse.processing.org/t/creating-an-array/8334>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [February 12, 2019, 9:04pm UTC](https://discourse.processing.org/t/creating-an-array/8334 "2019-02-12T21:04:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Awal](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Awal](https://discourse.processing.org/u/Awal)\
**Post date:** [February 12, 2019, 9:04pm UTC](https://discourse.processing.org/t/creating-an-array/8334/1 "2019-02-12T21:04:23Z")

</div>

Hi,  
I am working on a class assignment but I am stuck.

The assignment is

1. Create an **int** array called **salesFigure** that will hold 5 elements.
2. Use a for loop to print all the elements. (They should all be 0 since no information has been assigned.)
3. 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)
4. Print the array using a for loop

Here is what I have.

```auto
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

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [February 12, 2019, 9:30pm UTC](https://discourse.processing.org/t/creating-an-array/8334/2 "2019-02-12T21:30:27Z")

</div>

Hi Awal, you have forgot the size method:

```auto
for (int i = 0; i <salesFigures.size(); i++)

```

Keep us up to date!

---

<div class="post-metadata">

**Author:** ![Awal](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Awal](https://discourse.processing.org/u/Awal)\
**Post date:** [February 12, 2019, 10:14pm UTC](https://discourse.processing.org/t/creating-an-array/8334/3 "2019-02-12T22:14:07Z")

</div>

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?

```auto
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]);
}

```

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [February 12, 2019, 10:35pm UTC](https://discourse.processing.org/t/creating-an-array/8334/4 "2019-02-12T22:35:30Z")

</div>

Hops… I miss:

```auto
for (int i = 0; i &lt;salesFigures.length; i++)

```

Sorry but I’m writing by smartphone and I not tryed it…

---

<div class="post-metadata">

**Author:** ![Awal](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Awal](https://discourse.processing.org/u/Awal)\
**Post date:** [February 12, 2019, 11:44pm UTC](https://discourse.processing.org/t/creating-an-array/8334/5 "2019-02-12T23:44:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 12, 2019, 11:53pm UTC](https://discourse.processing.org/t/creating-an-array/8334/6 "2019-02-12T23:53:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Awal](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Awal](https://discourse.processing.org/u/Awal)\
**Post date:** [February 13, 2019, 12:35am UTC](https://discourse.processing.org/t/creating-an-array/8334/7 "2019-02-13T00:35:31Z")

</div>

Dennis, I got it!!! now on to the next part.

Thanks for your help. I may hit you up again if that’s ok.

---

<div class="post-metadata">

**Author:** ![Awal](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Awal](https://discourse.processing.org/u/Awal)\
**Post date:** [February 13, 2019, 12:36am UTC](https://discourse.processing.org/t/creating-an-array/8334/8 "2019-02-13T00:36:16Z")

</div>

Thanks Chrisir,  
I figured it out by watching the a Youtube on Arrays.

Thanks

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2019, 5:04pm UTC](https://discourse.processing.org/t/creating-an-array/8334/9 "2019-02-13T17:04:06Z")

</div>

Very good!  
Thanks for letting me know…
