Skip to content

Commit b641cbd

Browse files
committed
feat: add TwoDimensionalArrays example demonstrating 2D array declaration and printing
Implemented TwoDimensionalArrays.java to show declaration, initialization, and structured output of a 3x3 integer matrix without using loops. Illustrates the basics of accessing and printing multi-dimensional arrays. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent acb2e8c commit b641cbd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class TwoDimensionalArrays {
2+
public static void main(String[] args) {
3+
// Declare and initialize a 3x3 matrix with predefined values
4+
int[][] matrix = {
5+
{1, 2, 3}, // First row
6+
{4, 5, 6}, // Second row
7+
{7, 8, 9} // Third row
8+
};
9+
10+
// Print a message indicating matrix declaration
11+
System.out.println("Declaring a 3x3 matrix:");
12+
13+
// Print the matrix in a structured format (without using loops)
14+
System.out.println(matrix[0][0] + " " + matrix[0][1] + " " + matrix[0][2]); // Print first row
15+
System.out.println(matrix[1][0] + " " + matrix[1][1] + " " + matrix[1][2]); // Print second row
16+
System.out.println(matrix[2][0] + " " + matrix[2][1] + " " + matrix[2][2]); // Print third row
17+
}
18+
}

0 commit comments

Comments
 (0)