You are here: Home / Topics / Program for Sum of 2D array elements in Java

Program for Sum of 2D array elements in Java

Filed under: Java on 2023-08-23 06:48:23

// Sum Of Array Elements

public class SumOfArrayElements{

   public static void main(String[] args) {
       int i, j, sum = 0;
       int a[][] = {{10, 20, 30}, {40, 50, 60}, {70, 80, 90}};
       for (i = 0; i < 3; i++) {
           for (j = 0; j < 3; j++) {
               sum += a[i][j];
           }
       }
       System.out.println("Sum : "+sum);
   }
}


Output:

Sum : 450

 

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.