Implementing 2D Array Algorithms MCQ Practice

Question 1 of 10

A rink board stores frost scores. The code finds the maximum of the whole rectangle. What text does this Java code display?

int[][] frost = {
    {6, 2, 9},
    {11, 4, 1}
};
int max = frost[0][0];
for (int r = 0; r < frost.length; r++) {
    for (int c = 0; c < frost[0].length; c++) {
        if (frost[r][c] > max) {
            max = frost[r][c];
        }
    }
}
System.out.print(max);
  1. A. 9
  2. B. 11
  3. C. 6
  4. D. 4

Question 2 of 10

A pier log inspects only row 1 for its minimum. What text does this Java code display?

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

Question 3 of 10

A bakery tray totals every cell in the rectangle. What text does this Java code display?

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

Question 4 of 10

A weather loft averages column 0 using integer division. What text does this Java code display?

int[][] wind = {
    {10, 3},
    {7, 8},
    {6, 2}
};
int sum = 0;
for (int r = 0; r < wind.length; r++) {
    sum += wind[r][0];
}
System.out.print(sum / wind.length);
  1. A. 7
  2. B. 8
  3. C. 4
  4. D. 23

Question 5 of 10

A lantern row checks whether column 2 contains at least one multiple of 5. What text does this Java code display?

int[][] lamps = {
    {4, 9, 12},
    {8, 3, 20},
    {6, 1, 7}
};
boolean found = false;
for (int r = 0; r < lamps.length; r++) {
    if (lamps[r][2] % 5 == 0) {
        found = true;
    }
}
System.out.print(found);
  1. A. false
  2. B. true
  3. C. 20
  4. D. 12

Question 6 of 10

A quilt check tests whether every cell in the whole grid is even. What text does this Java code display?

int[][] quilt = {
    {2, 8, 4},
    {6, 10, 5}
};
boolean allEven = true;
for (int r = 0; r < quilt.length; r++) {
    for (int c = 0; c < quilt[0].length; c++) {
        if (quilt[r][c] % 2 != 0) {
            allEven = false;
        }
    }
}
System.out.print(allEven);
  1. A. true
  2. B. false
  3. C. 5
  4. D. 2

Question 7 of 10

A seed tray counts how many values in the subsection rows 1-2 and columns 0-1 are less than 4. What text does this Java code display?

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

Question 8 of 10

A chimney log counts consecutive vertical pairs in column 0 that strictly increase downward. What text does this Java code display?

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

Question 9 of 10

A locker wall reports whether the whole rectangle contains any duplicated value. What text does this Java code display?

int[][] lockers = {
    {3, 8, 1},
    {5, 8, 2}
};
boolean dup = false;
for (int r = 0; r < lockers.length; r++) {
    for (int c = 0; c < lockers[0].length; c++) {
        int v = lockers[r][c];
        int seen = 0;
        for (int r2 = 0; r2 < lockers.length; r2++) {
            for (int c2 = 0; c2 < lockers[0].length; c2++) {
                if (lockers[r2][c2] == v) {
                    seen++;
                }
            }
        }
        if (seen > 1) {
            dup = true;
        }
    }
}
System.out.print(dup);
  1. A. false
  2. B. true
  3. C. 8
  4. D. 3

Question 10 of 10

A hoist rotates column 1 one place upward, wrapping the top value to the bottom. What text does this Java code display?

int[][] hoist = {
    {4, 10, 1},
    {5, 20, 2},
    {6, 30, 3}
};
int top = hoist[0][1];
for (int r = 0; r < hoist.length - 1; r++) {
    hoist[r][1] = hoist[r + 1][1];
}
hoist[hoist.length - 1][1] = top;
System.out.print(hoist[0][1] + " " + hoist[1][1] + " " + hoist[2][1]);
  1. A. 20 30 10
  2. B. 30 10 20
  3. C. 10 20 30
  4. D. 30 20 10