提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
计算数组元素的平均值
public class Main { public static void main(String[] args) {/*时代Java - N o w J a v a . c o m 提供*/ int[] numbers = new int[]{110,120,115,25,116,60,110}; int sum = 0; for(int i=0; i < numbers.length ; i++) sum = sum + numbers[i]; //calculate average value double average = sum / numbers.length; System.out.println("Average value of array elements is : " + average); } }