java实现一个方法 sum, 以数组为参数, 求数组所有元素之和.

public class Test40{
    public static void main(String[] args) {
        int[] arr={1,2,3};
        int ret=sum(arr);
        System.out.println(ret);
    }
    public static int sum(int[] a){
        int ret2=0;
        for(int x:a){
            ret2+=x;
        }
        return ret2;
    }
}
发布了87 篇原创文章 · 获赞 2 · 访问量 714

猜你喜欢

转载自blog.csdn.net/Nabandon/article/details/103756636
今日推荐