集册 Java实例教程 数组元素之和

数组元素之和

欢马劈雪     最近更新时间:2020-01-02 10:19:05

389
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
数组元素之和


//package com.nowjava;
/*
来 自*
 N o w  J a v a  . c o m
*/


public class Main {

    public static void main(String[] argv) throws Exception {

        int[] a = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };

        System.out.println(sum(a));

    }


    /**

     * sum of array elements

     * @param a

     * @return

     */

    public static int sum(int[] a) {

        int retval = 0;

        
展开阅读全文