nonSquare 4

Complete the method nonSquare, which returns a two-dimensional array as shown below. Do not hardcode this one please :). You're practicing how to use a loop to traverse the 2D array and assign its elements.

1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20

2D Array Declaration and Instantiation:

type[][] name = new type[# rows][# cols];

ex:
int[][] data = new int[3][2];

Quick Traversal:
This problem is about setting up your 2D array traversal! In AP CSA, the go-to traditional traversal is known as the row-major traversal. 

for(int row = 0; row < my2D.length; row++){
    for(int col = 0; col < my2D[row].length; col++){
       System.out.println(my2D[row][col]);
    }
}
Type your solution        
Skills Practiced:
3.C
3.E
4.A
4.B
Copyright © StudyCS 2024 All rights reserved.