Answer:
- public class Main {
-
- public static void main (String [] args) {
- String [][] list1 = new String[3][2];
-
- int[][] nums = {{1,2,3}, {4, 5, 6}};
-
- int z[][] = {{1,2,3,4}, {5, 6, 7, 8, 9}};
- System.out.println(z.length);
-
- for(int i=0; i < z.length; i++){
- System.out.println(z[i].length);
- }
- }
- }
Step-by-step explanation:
Solution code is written in Java.
The best way to review the array topic is to create a Main program to write the relevant codes to create and manipulate array.
Firstly, create a two dimensional array using double square bracket syntax [] [] (Line 4). We put row and column number in each of the square bracket (new String [3] [2] ). The statement in Line 4 will create a two dimensional array with 3 rows and 2 columns.
We can also directly initialize a two dimensional array by enclosing the elements inside the curly brackets (Line 6).
To get the number of row, we can use length property. For example, z.length will give the number of rows in the two dimensional z array (Line 8-9).
To get the number of columns in each row, we can create a for loop to traverse through each row and use the i index to address each array row and use dot syntax to get the length property of each row which equivalent to number of columns (Line 11 - 13).