0

Hey, I'm kinda crappy with arrays.

int [] myArray = new int[5];
				myArray[0] = num1;   // initialize # of cols
				myArray[1] = num2;   // in each row
				myArray[2] = num3;
				myArray[3] = num4;
				myArray[4] = num5;

I want to use a for statement, to add these 5 things together, and then divide that by 5. Any idea how I can do that?

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by sonicx2218
0
int[] ar = {num1, num2, num3, num4, num5};
				sum = 0;
				for (int d : ar)
				{  // d gets successively each value in ar.
				    sum += d;
				    avg = sum / 5;

got it myself. Just changed the style to this

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.