Java Multi-Dimensional Arrays
📊 Java Multi-Dimensional Arrays (2D Arrays)
A multi-dimensional array is an array of arrays. The most common type is the 2D array, which is similar to a table or matrix.
✅ 1. Declaration and Initialization
Syntax:
Or combined:
Example 1: 2D Array Declaration and Initialization
✅ 2. Looping Through a 2D Array
Using nested for loops:
📌 Output:
✅ 3. Sum of All Elements in 2D Array
📌 Output:
✅ 4. Row-wise Sum
📌 Output:
✅ 5. Column-wise Sum
📌 Output:
✅ 6. Real-Life Example: Seat Booking in Theater
📌 Output:
🧠Key Points
-
A 2D array is an array of arrays.
-
Use nested loops to traverse rows and columns.
-
Useful for tables, matrices, grids, seating arrangements, etc.
-
Can also be extended to 3D arrays or higher.
