Skip to content

Commit 720bed6

Browse files
committed
feat: Print elements of a 2D array with variable column lengths (jagged array)
🧠 Logic: - Initializes a 2D jagged array where each row has a different number of columns. - Iterates through each row and its corresponding columns using nested loops. - Prints elements row by row, handling non-uniform (non-rectangular) structure safely. Signed-off-by: Somesh diwan <[email protected]>
1 parent 8cb16c0 commit 720bed6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Section9ArrayAB/Array IMP/ColNoFixed.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ public static void main(String[] args) {
66
{7, 8, 9}
77
};
88

9-
for (int row = 0; row < arr.length; row++) {
10-
for (int col = 0; col < arr[row].length; col++) {
9+
for (int row = 0; row < arr.length; row++)
10+
{
11+
for (int col = 0; col < arr[row].length; col++)
12+
{
1113
System.out.print(arr[row][col] + " ");
1214
}
1315
System.out.println();

0 commit comments

Comments
 (0)