1/19
20 question-and-answer flashcards reviewing key concepts about two-dimensional arrays in Java.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the simplest form of a multidimensional array in Java that is essentially an array of one-dimensional arrays?
A two-dimensional array, also called a matrix or table.
How do you declare a two-dimensional integer array named matriz in Java?
int[][] matriz;
In the statement "int[][] matriz = new int[3][4];", what do the numbers 3 and 4 represent?
3 represents the number of rows and 4 represents the number of columns, so the matrix size is 3×4.
Which Java keyword is required to allocate memory for an array after it is declared?
new
Write the Java code to create and initialize a 3×3 matrix containing the numbers 1 to 9 in order.
int[][] matrix = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
Which property provides the total number of rows in a two-dimensional array named mat?
mat.length
Which expression gives the total number of columns in the first row of a two-dimensional array mat?
mat[0].length
How do you access the element located at row index f and column index c in array a?
a[f][c]
What runtime exception occurs if you try to access a matrix element with an invalid index?
ArrayIndexOutOfBoundsException
Describe the standard nested for loop structure for traversing all elements row by row in a matrix.
Use an outer for loop over the rows and an inner for loop over the columns within each row.
How would you modify the traversal to visit the matrix column by column instead?
Make the outer loop iterate over columns and the inner loop iterate over rows.
How does an enhanced for-each loop traverse a two-dimensional array?
The outer for-each iterates through each row array, and the inner for-each iterates through every value in that row.
In the declaration "int a[][], b;", which variables are two-dimensional arrays and which are simple ints?
"a" is a two-dimensional int array; "b" is a simple int variable.
In the declaration "int[][] c, d;", what kinds of variables are c and d?
Both c and d are two-dimensional int arrays.
For the 4×4 magic square shown in the lecture, what is the magic constant (the common sum)?
34
What does the dimension notation m × n signify for a matrix?
A matrix with m rows and n columns.
What is the main difference between storing related data in a matrix versus using parallel arrays?
A matrix stores related items together in one 2-D structure, while parallel arrays split related fields into separate 1-D arrays that must be kept synchronized.
Provide the Java statement that stores the value 33 in row 0, column 1 of int[][] matriz.
matriz[0][1] = 33;
When iterating over rows with index f, what column index should you use to print the main diagonal element?
Use the same index as the row: matriz[f][f].
Which part of a two-dimensional array declaration (e.g., int[][]) indicates that the variable has two dimensions?
The two pairs of square brackets [][] following the data type.