Implementing Array Algorithms MCQ Practice

Question 1 of 10

Pebblewick Quarry tracks boulder masses. What text does this Java code display?

int[] mass = {6, 2, 9, 4};
int largest = mass[0];
for (int i = 1; i < mass.length; i++) {
    if (mass[i] > largest) {
        largest = mass[i];
    }
}
System.out.print(largest);
  1. A. 6
  2. B. 4
  3. C. 9
  4. D. 2

Question 2 of 10

Mossbank Pottery stores glaze thicknesses. What text does this Java code display?

int[] coat = {18, 11, 15, 11};
int thin = coat[0];
for (int i = 1; i < coat.length; i++) {
    if (coat[i] < thin) {
        thin = coat[i];
    }
}
System.out.print(thin);
  1. A. 11
  2. B. 18
  3. C. 15
  4. D. 4

Question 3 of 10

Copperwick Depot logs tram-car loads. The table is the array. What text does this Java code display?

Index Load
0 10
1 20
2 5
int[] load = {10, 20, 5};
int sum = 0;
for (int i = 0; i < load.length; i++) {
    sum += load[i];
}
System.out.print(sum);
System.out.print(":");
System.out.print(sum / load.length);
  1. A. 35:10
  2. B. 30:10
  3. C. 35:11
  4. D. 35:20

Question 4 of 10

Larkfen Marsh checks whether at least one depth reading is even. What text does this Java code display?

int[] depth = {1, 3, 5};
boolean even = false;
for (int i = 0; i < depth.length; i++) {
    if (depth[i] % 2 == 0) {
        even = true;
    }
}
System.out.print(even);
  1. A. true
  2. B. false
  3. C. 5
  4. D. 0

Question 5 of 10

Ashgrove Kiln tests whether every firing hour is even. What text does this Java code display?

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

Question 6 of 10

Bramblewick Orchard counts crate labels that are multiples of 7. What text does this Java code display?

int[] labels = {7, 14, 21, 8, 35};
int count = 0;
for (int i = 0; i < labels.length; i++) {
    if (labels[i] % 7 == 0) {
        count++;
    }
}
System.out.print(count);
  1. A. 5
  2. B. 1
  3. C. 4
  4. D. 3

Question 7 of 10

Nettlewick Apiary counts neighboring hive weights that match. What text does this Java code display?

int[] grams = {2, 5, 5, 5, 1};
int twins = 0;
for (int i = 0; i < grams.length - 1; i++) {
    if (grams[i] == grams[i + 1]) {
        twins++;
    }
}
System.out.print(twins);
  1. A. 3
  2. B. 1
  3. C. 0
  4. D. 2

Question 8 of 10

Willowwick Pond checks for any repeated depth, including values that are not neighbors. What text does this Java code display?

int[] pond = {4, 1, 9, 4};
boolean repeat = false;
for (int i = 0; i < pond.length; i++) {
    for (int j = i + 1; j < pond.length; j++) {
        if (pond[i] == pond[j]) {
            repeat = true;
        }
    }
}
System.out.print(repeat);
  1. A. false
  2. B. true
  3. C. 4
  4. D. 2

Question 9 of 10

Driftwick Harbor rotates buoy IDs one slot to the right. What text does this Java code display?

int[] buoy = {1, 6, 8, 3};
int last = buoy[buoy.length - 1];
for (int i = buoy.length - 1; i > 0; i--) {
    buoy[i] = buoy[i - 1];
}
buoy[0] = last;
for (int i = 0; i < buoy.length; i++) {
    System.out.print(buoy[i]);
}
  1. A. 1683
  2. B. 6813
  3. C. 3168
  4. D. 3861

Question 10 of 10

Amberwick Studio reverses resin-vial counts in place. What text does this Java code display?

int[] vials = {2, 7, 4, 9, 5};
for (int i = 0; i < vials.length / 2; i++) {
    int temp = vials[i];
    vials[i] = vials[vials.length - 1 - i];
    vials[vials.length - 1 - i] = temp;
}
for (int i = 0; i < vials.length; i++) {
    System.out.print(vials[i]);
}
  1. A. 59472
  2. B. 27495
  3. C. 57924
  4. D. 24975