Java Chapter 8 Multidimensional and
Ragged Arrays Questions with Detailed
Verified Answers (100% Correct Answers)
/Already Graded A+
How are elements in two-dimensional arrays accessed
Ans: through a row and column index
how do you declare a new two-dimensional array?
Ans: elementType[][] arrayName;
how would you declare a two-dimensional array variable "matrix" of int values?
Ans: int[][] matrix;
How would you create a two-dimensional array variable "matrix" of 5 rows and 5 columns
Ans: int[][] matrix = new int[5][5];
Initialize a new, 3x3 two-dimensional array named arr with ones in each place
Ans: int[][] arr = { {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, }
How do you get the length of the one-dimensional array at index 0 of array arr?
Ans: arr[0].length
What is a ragged array?
Ans: A two-dimensional array with rows of different lengths
How do you initialize a 2D array without knowing the length of each row
Ans: int[][] arr = new int[numRows][];