File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Help with arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with arrays" Watch "Help with arrays" New topic

Help with arrays

Shawn Houston

Joined: Oct 14, 2004
Posts: 22
Ok i have a program that takes 4 orchards over a 5 year span. I need to get the average of each orchard. Which I i need to get the Total of the 4 orchards for each of the 5 years..then the average for each year which I'm having a real trouble doing.

I just can't seem to get the totals for each seperate year and the averages.
What i thinking is I have to:
for(i = 0; i < 4; i++) {
for(j = 0; j < 5; j++)
year_total[i] += peach[0][0] +peach[0][1] + peach[0][2] + peach[0][3];
year_avg[i] = (float)(year_total[i] / 4.0);

For each consecutive year..but when i do that it adds both years then averages them. Not sure where I'm going wrong here nor how to put all the years into 1 for statement if its even possible.
Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97

Something a little different but a little the same:

[ November 29, 2004: Message edited by: Jimmy Die ]

Jimmy Die
I agree. Here's the link:
subject: Help with arrays
It's not a secret anymore!