Computer Science, asked by krishaang2005, 5 hours ago

Write a program to input and store integer elements in a double dimensional array of size 3×4 and find the sum of all the elements.
7 3 4
5 4 6
6 9 4
Sum of all the elements: 4 and Sum of diagonal elements: 14

Answers

Answered by shilpa85475
6

For the given problem:

In the array elements of the array there are 9 elements. The sum of all the elements is calculated.

Explanation:

import java.util.Scanner;

public class abc

{

   public static void main(String args[])

{

       Scanner in = new Scanner(System.in);

       int arr[] = new int[20];

       System.out.println("Enter the 9 numbers:");

       for (int i = 0; i < 9; i++)

{

           arr[i] = in.nextInt();

       }

       int min = arr[0], max = arr[0], sum = 0;

       for (int i = 0; i < arr.length; i++)

{

           

           sum += arr[i];

       }

       

     

       System.out.println("Sum = " + sum);

   }

}

Similar questions