Arrays-2D

Q: You want to create a table that looks like this:Which of the following options will work?
A: double[][] table = { {12, -9, 8},  {7, 14},  {-32, -1, 0} };
Q: Which of the following statements assigns the letter S to the third row and first column of a two-dimensional array named strGrid (assuming row-major order)?
A: strGrid[2][0] = "S";
Q: What will be the output of the following Java code?
class array_output 
    {
        public static void main(String args[]) 
        {
            int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};
            int sum = 0;
            for (int i = 0; i < 3; ++i)
                for (int j = 0; j <  3 ; ++j)
                    sum = sum + array_variable[i][j];
            System.out.print(sum / 5);
        } 
    }
A: 9
Q: Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length?
A: 3 and 2
Q: How many elements are in the array matrix (int[][] matrix = new int [5] [5])?
A: 25
Q: Given a 2D array matrix with dimensions M x N, which of the following Java code snippets correctly prints the elements of the array in row-major order (i.e., from left to right, top to bottom)?
A: for (int i = 0; i < M; i++) {  for (int j = 0; j < N; j++) {    System.out.print(matrix[i][j] + " ");  }}
Q: Examine the following:What is in values [3] and [0]?
double[][] values =
  { {1.2, 9.0, 3.2},
    {9.2, 0.5, 1.5, -1.2},
    {7.3, 7.9, 4.8} } ;
A: There is no such array element
Q: Given:Which of the following fragments prints out every element of items?
int[][] items =
  { {0, 1, 3, 4},
    {4, 3, 99, 0, 7 },
    {3, 2} } ;
A: for ( int row=0; row < items.length; row++ ){ System.out.println(); for ( int col=0; col < items[row].length; col++ )  System.out.print( items[row][col] + " ");}
Q: Which of the following statements is correct? 
A: char[][] charArray = {{'a', 'b'}, {'c', 'd'}};
Q: Given the following: What is the value of things.length ?
double[][] things =
  { {1.2, 9.0},
    {9.2, 0.5, 0.0},
    {7.3, 7.9, 1.2, 3.9} } ;
A: 3
Q: What is the index variable for the element in the first row and first column of array a?
A: a[0][0]
Q:  Assume double[][] x = new double[4][5], what are x.length and x[2].length?
A: 4 and 5
Q: Consider a 2D array in Java with dimensions M x N, where M represents the number of rows and N represents the number of columns. The array is filled with integers such that the element at index (i, j) is denoted by arr[i][j]. The indices are 0-based, i.e., the first row and first column have index 0. Which of the following options correctly represents the code to calculate the sum of all elements in the array?
A: int sum = 0;for (int i = 0; i < M; i++) {  for (int j = 0; j < N; j++) {    sum += arr[i][j];  }}
Q: What is the output of the following program?
public class Main 
{ 
	public static void main(String args[]) 
	{ 
		int arr[][] = new int[4][]; 
		arr[0] = new int[1]; 
		arr[1] = new int[2]; 
		arr[2] = new int[3]; 
		arr[3] = new int[4]; 
        int i, j, k = 0; 
		for (i = 0; i < 4; i++) 
		{ 
			for (j = 0; j < i + 1; j++) 
			{ 
				arr[i][j] = k; 
				k++; 
			} 
		} 
		for (i = 0; i < 4; i++) 
		{ 
			for (j = 0; j < i + 1; j++) 
			{ 
				System.out.print(" " + arr[i][j]); 
				k++; 
			} 
			System.out.println(); 
		} 
	} 
} 

A: 01 23 4 56 7 8 9
Q: What will be the output of the following code?
class multidimention_array 
    {
        public static void main(String args[])
        {
            int arr[][] = new int[3][];
            arr[0] = new int[1];
            arr[1] = new int[2];
            arr[2] = new int[3];               
	    int sum = 0;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    arr[i][j] = j + 1;
	    for (int i = 0; i < 3; ++i) 
	        for (int j = 0; j < i + 1; ++j)
                    sum += arr[i][j];
	    System.out.print(sum); 	
        } 
    }
A: 10