提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
计算数组元素的总和。
public class Main { public static void main(String[] args)//来 自 n o w j a v a . c o m { int[] array = {817, 681, 94, 110, 831, 178, 185, 191, 76, 87}; int total = 0; // add each element's value to total for (int counter = 0; counter < array.length; counter++) total += array[counter]; System.out.printf("Total of array elements: %d%n", total); } }