Home > Java > javaTutorial > body text

How to implement summation of array elements in Java

王林
Release: 2023-05-08 20:40:06
forward
1206 people have browsed it

Sum of elements in an array

public class T02 {
    public static void main(String[] args) {
        int[][]arr=new int[][]{{1,2,3,4,5},{1,2,3,5},{8,9,7}};
        int sum=0;
        for(int i=0;i< arr.length;i++){
            for(int j=0;j<arr[i].length;j++){
               sum=arr[i][j]+sum;
            }
        }
        System.out.println("sum="+sum);
    }
}
//和为50
Copy after login

The above is the detailed content of How to implement summation of array elements in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!