Due to the print book page limit, we cannot inlcude all good CheckPoint questions in the physical book. The CheckPoint on this Website may contain extra questions not printed in the book. The questions in some sections may have been reordered as a result. Nevertheless, it is easy to find the CheckPoint questions in the book on this Website. Please send suggestions and errata to Dr. Liang at y.daniel.liang@gmail.com. Indicate the book, edition, and question number in your email. Thanks!

Chapter 8 Check Point Questions

Section 8.2
8.2.1
Declare an array reference variable for a two-dimensional array of int values, create a 4 × 5 int matrix, and assign it to the variable.
8.2.2
Can the rows in a two-dimensional array have different lengths?
8.2.3
What is the output of the following code?
int[][] array = new int[5][6];
int[] x = {1, 2};
array[0] = x;
System.out.println("array[0][1] is " + array[0][1]);
8.2.4
Which of the following statements are valid?
int[][] r = new int[2]; 	
int[] x = new int[];
int[][] y = new int[3][];
int[][] z = {{1, 2}};
int[][] m = {{1, 2}, {2, 3}};
int[][] n = {{1, 2}, {2, 3}, };
Section 8.3
8.3.1
Show the output of the following code:
int[][] array = {{1, 2}, {3, 4}, {5, 6}};
for (int i = array.length - 1; i >= 0; i--) {
  for (int j = array[i].length - 1; j >= 0; j--)
    System.out.print(array[i][j] + " ");
  System.out.println();
}
8.3.2
Show the output of the following code:
int[][] array = {{1, 2}, {3, 4}, {5, 6}};
int sum = 0;
for (int i = 0; i < array.length; i++) 
  sum += array[i][0];
System.out.println(sum);
Section 8.4
8.4.1
Show the output of the following code:
public class Test {
  public static void main(String[] args) {
    int[][] array = {{1, 2, 3, 4}, {5, 6, 7, 8}};
    System.out.println(m1(array)[0]);
    System.out.println(m1(array)[1]);
  }

  public static int[] m1(int[][] m) {
    int[] result = new int[2];
    result[0] = m.length;
    result[1] = m[0].length;
    return result;
  }
}
Section 8.5
8.5.1
8.5.1 How do you modify the code so that it also displays the highest count and the student with the highest count?
Section 8.6
8.6.1
What happens if the input has only one point?
Section 8.7
8.7.1
What happens if the code in line 51 in Listing 8.4 is changed to
if (row != i && col != j && grid[row][col] == grid[i][j])
Section 8.8
8.8.1
Declare an array variable for a three-dimensional array, create a 4 × 6 × 5 int array, and assign its reference to the variable.
8.8.2
Assume char[][][] x = new char[12][5][2], how many elements are in the array? What are x.length, x[2].length, and x[0][0].length?
8.8.3
Show the output of the following code:
int[][][] array = {{{1, 2}, {3, 4}}, {{5, 6},{7, 8}}};
System.out.println(array[0][0][0]);
System.out.println(array[1][1][1]);