public class Main {
public static void main(String[] args) {
int[] intArray = new int[] { 1, 2, 3, 4, 5 };
// calculate sum
int sum = 0;
for (int i = 0; i < intArray.length; i++){
sum = sum + intArray[i];
}
// calculate average
double average = sum / intArray.length;
System.out.println("average: " + average);
}
}
The output:
average: 3.0
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |