Storing in an Array
I am writing this program that uses a global int array to simulate turnstile counts. Each element of the array represents the count on a turnstile. There are 10 turnstiles and I must run a program that has 1000 people passing through these 10 turnstiles randomly.
THe output must be like this:
counter = 23; (23 people going through this turnstile
counter = 56;
counter = 89;
and so on up to
counter = 34;
In my program I can't manage to place the randomly created numbers to only be placed in the 10 different elements. It seems that when I do a loop to run 1000times it prints out the individual counters 1000 times each and then has values beside them. How do I just simulate how many times a counter has been randomly "walked through" and then add that just to the value inside of that element.
I also need to create a function that returns the sum and average of the 10 array elements and then display these to screen as well.
Here is my code and thanks for your time:
public static void main(String args)
intcounter1 = new int;
for(int i = 0;i<counter2.length;i++)
counter2[i] = 0;
for (int i=0;i<counter1.length;i++)
for (int j = 0; j < 20; j++)
int patron = (int)(Math.random() * 10);
System.out.println("counter [" + i + "] = " +counter2[+ patron]);
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL