Implementing 2D Array Algorithms MCQ Practice

Question 1 of 10

A lantern booth stores glow scores in a rectangular tray. What text does this Java code display?

int[][] glow = {
    {8, 3, 9},
    {4, 7, 2}
};
int min = glow[0][0];
for (int r = 0; r < glow.length; r++) {
    for (int c = 0; c < glow[0].length; c++) {
        if (glow[r][c] < min) {
            min = glow[r][c];
        }
    }
}
System.out.print(min);
  1. A. 3
  2. B. 8
  3. C. 2
  4. D. 4

Question 2 of 10

A ferry chalkboard tracks wait minutes. The code inspects only column 1. What text does this Java code display?

int[][] wait = {
    {5, 11, 4},
    {9, 8, 16},
    {7, 15, 3}
};
int max = wait[0][1];
for (int r = 1; r < wait.length; r++) {
    if (wait[r][1] > max) {
        max = wait[r][1];
    }
}
System.out.print(max);
  1. A. 11
  2. B. 15
  3. C. 16
  4. D. 9

Question 3 of 10

An orchard shed totals crates in row 1. What text does this Java code display?

int[][] crates = {
    {2, 5, 1},
    {4, 3, 6}
};
int sum = 0;
for (int c = 0; c < crates[1].length; c++) {
    sum += crates[1][c];
}
System.out.print(sum);
  1. A. 8
  2. B. 13
  3. C. 6
  4. D. 7

Question 4 of 10

A greenhouse averages a 2-by-2 subsection: rows 0 through 1 and columns 1 through 2. The tray is shown below. What text does this Java code display?

row col 0 col 1 col 2
row 0 9 8 7
row 1 5 4 3
row 2 2 1 0
int[][] heat = {
    {9, 8, 7},
    {5, 4, 3},
    {2, 1, 0}
};
int sum = 0;
int n = 0;
for (int r = 0; r <= 1; r++) {
    for (int c = 1; c <= 2; c++) {
        sum += heat[r][c];
        n++;
    }
}
System.out.print(sum / n);
  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 8

Question 5 of 10

A stamp drawer reports whether at least one score in the whole grid is odd. What text does this Java code display?

int[][] stamps = {
    {2, 4, 6},
    {8, 1, 10}
};
boolean found = false;
for (int r = 0; r < stamps.length; r++) {
    for (int c = 0; c < stamps[0].length; c++) {
        if (stamps[r][c] % 2 == 1) {
            found = true;
        }
    }
}
if (found) {
    System.out.print("yes");
} else {
    System.out.print("no");
}
  1. A. no
  2. B. yes
  3. C. 1
  4. D. true

Question 6 of 10

A tide board checks whether every value in row 0 is positive. What text does this Java code display?

int[][] tide = {
    {3, 5, 2},
    {-1, 4, 8}
};
boolean allPos = true;
for (int c = 0; c < tide[0].length; c++) {
    if (tide[0][c] <= 0) {
        allPos = false;
    }
}
if (allPos) {
    System.out.print("all");
} else {
    System.out.print("mixed");
}
  1. A. all
  2. B. mixed
  3. C. 3
  4. D. false

Question 7 of 10

A bean loft counts how many values in column 2 are greater than 5. What text does this Java code display?

int[][] beans = {
    {4, 9, 8},
    {8, 1, 3},
    {2, 7, 11}
};
int count = 0;
for (int r = 0; r < beans.length; r++) {
    if (beans[r][2] > 5) {
        count++;
    }
}
System.out.print(count);
  1. A. 2
  2. B. 5
  3. C. 1
  4. D. 3

Question 8 of 10

A boardwalk counts consecutive pairs in row 1 where the left value is less than the right value. What text does this Java code display?

int[][] path = {
    {5, 1, 4, 2},
    {3, 8, 6, 9}
};
int pairs = 0;
for (int c = 0; c < path[1].length - 1; c++) {
    if (path[1][c] < path[1][c + 1]) {
        pairs++;
    }
}
System.out.print(pairs);
  1. A. 2
  2. B. 3
  3. C. 1
  4. D. 4

Question 9 of 10

A tile table checks the 2-by-2 subsection in rows 0-1 and columns 0-1 for a duplicated value. What text does this Java code display?

int[][] tiles = {
    {4, 7, 4},
    {7, 2, 9}
};
boolean dup = false;
for (int r = 0; r < 2; r++) {
    for (int c = 0; c < 2; c++) {
        int v = tiles[r][c];
        int seen = 0;
        for (int r2 = 0; r2 < 2; r2++) {
            for (int c2 = 0; c2 < 2; c2++) {
                if (tiles[r2][c2] == v) {
                    seen++;
                }
            }
        }
        if (seen > 1) {
            dup = true;
        }
    }
}
if (dup) {
    System.out.print("dup");
} else {
    System.out.print("unique");
}
  1. A. dup
  2. B. unique
  3. C. 4
  4. D. 7

Question 10 of 10

A pastry belt rotates row 0 one place to the left, wrapping the first value to the end. What text does this Java code display?

int[][] belt = {
    {1, 2, 3, 4},
    {9, 8, 7, 6}
};
int first = belt[0][0];
for (int c = 0; c < belt[0].length - 1; c++) {
    belt[0][c] = belt[0][c + 1];
}
belt[0][belt[0].length - 1] = first;
System.out.print(belt[0][0] + " " + belt[0][1] + " " + belt[0][2] + " " + belt[0][3]);
  1. A. 2 3 4 1
  2. B. 4 1 2 3
  3. C. 1 2 3 4
  4. D. 4 3 2 1