# help with and array of objects

• 01-22-2011, 09:51 PM
hoosierfan24
help with and array of objects
ok so i have and array of objects called coordinates and its size is 1000 and i want to input two random numbers into each slot. How would i set up a loop to do this?
• 01-22-2011, 10:07 PM
Fubarable
Quote:

Originally Posted by hoosierfan24
ok so i have and array of objects called coordinates and its size is 1000 and i want to input two random numbers into each slot. How would i set up a loop to do this?

Much luck.
• 01-22-2011, 10:30 PM
hoosierfan24
here is a better example of the problem

Code:

``` Point [] coordinates = new Point[1000];                 coordinates[0] = new Point (Math.random() * 50 , Math.random() * 50);                 coordinates[1] = new Point (Math.random() * 50 , Math.random() * 50);```
i want to put Math.random() * 50 for the paramaters of each object in the array, is there just another way to do it without creating a 1000 different objects individually
• 01-22-2011, 10:53 PM
user0
Quote:

Originally Posted by hoosierfan24
here is a better example of the problem

Code:

``` Point [] coordinates = new Point[1000];                 coordinates[0] = new Point (Math.random() * 50 , Math.random() * 50);                 coordinates[1] = new Point (Math.random() * 50 , Math.random() * 50);```
i want to put Math.random() * 50 for the paramaters of each object in the array, is there just another way to do it without creating a 1000 different objects individually

You can loop through the array using a for loop:
Code:

```for(int i = 0; i < coordinates.length; i++) { // loop through each element (not "slot" as you call it)   coordinates[i] = something; // do your assignment here }```
• 01-22-2011, 10:56 PM
Fubarable
Quote:

Originally Posted by hoosierfan24
``` Point [] coordinates = new Point[1000];                 coordinates[0] = new Point (Math.random() * 50 , Math.random() * 50);                 coordinates[1] = new Point (Math.random() * 50 , Math.random() * 50);```