Home Java Programming Language / Programs / Question 8
🚀 Programming Example

Question 8

👁 103 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Question 8

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

💻 Program Code

import java.util.Scanner;

public class RansariDDASum
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        
        int arr[][] = new int[4][4];
        long sum = 0;
        
        System.out.println("Enter the elements of 4x4 array:");
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                arr[i][j] = in.nextInt();
            }
        }
        
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                sum += arr[i][j];
            }
        }
        
        System.out.println("Sum of all the elements: " + sum);
    }
}
                        
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.