Implementing Array Algorithms MCQ Practice

Question 1 of 10

Brinewick Pier logs kelp bundle weights in kilograms. What text does this Java code display?

int[] kelp = {12, 9, 15, 8, 11};
int least = kelp[0];
for (int i = 1; i < kelp.length; i++) {
    if (kelp[i] < least) {
        least = kelp[i];
    }
}
System.out.print(least);
  1. A. 12
  2. B. 9
  3. C. 8
  4. D. 15

Question 2 of 10

Glimmerwick Fair stores lantern burn hours. What text does this Java code display?

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

Question 3 of 10

Maplewick Track records four baton-pass times in seconds. What text does this Java code display?

int[] times = {3, 5, 4, 6};
int total = 0;
for (int i = 0; i < times.length; i++) {
    total += times[i];
}
System.out.print(total);
  1. A. 4
  2. B. 6
  3. C. 15
  4. D. 18

Question 4 of 10

Emberford Studio logs three kiln temperatures. The table shows the stored values. What text does this Java code display?

Slot Temperature
0 21
1 27
2 12
int[] temps = {21, 27, 12};
int sum = 0;
for (int i = 0; i < temps.length; i++) {
    sum += temps[i];
}
System.out.print(sum / temps.length);
  1. A. 60
  2. B. 20
  3. C. 21
  4. D. 27

Question 5 of 10

Saltwick Inlet checks whether any tide reading is above 6. What text does this Java code display?

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

Question 6 of 10

Cloudwick Carnival tests whether every balloon loft is at least 10. What text does this Java code display?

int[] loft = {12, 14, 11, 16};
boolean allHigh = true;
for (int i = 0; i < loft.length; i++) {
    if (loft[i] < 10) {
        allHigh = false;
    }
}
System.out.print(allHigh);
  1. A. true
  2. B. false
  3. C. 4
  4. D. 12

Question 7 of 10

Thimbleford Guild counts quilt panels with at least 10 stitches. What text does this Java code display?

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

Question 8 of 10

Orchardwick Mill counts neighboring cider vats that hold the same number of gallons. What text does this Java code display?

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

Question 9 of 10

Northwick Lighthouse checks whether any blink count is stored more than once, even if the copies are not next to each other. What text does this Java code display?

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

Question 10 of 10

Fernwick Nursery shifts seed-packet masses one slot left and writes 0 into the last slot. What text does this Java code display?

int[] packs = {5, 2, 9, 4};
for (int i = 0; i < packs.length - 1; i++) {
    packs[i] = packs[i + 1];
}
packs[packs.length - 1] = 0;
for (int i = 0; i < packs.length; i++) {
    System.out.print(packs[i]);
}
  1. A. 5294
  2. B. 2940
  3. C. 4529
  4. D. 4952