A Java warehouse program processes an array whose first and last positions refer to the same Box. Both loops visit positions from index zero to index two. What final value is stored in total? Answer in units as an exact integer.
class Box { int units; Box(int units) { this.units = units; } } Box shared = new Box(10); Box[] route = {shared, new Box(7), shared}; for (Box box : route) { if (box.units >= 8) { box.units -= 2; } } int total = 0; for (Box box : route) { total += box.units; }
Unlock full course notes by signing up
Copy the list, then change its contents
An inventory application executes the Java fragment below. The ArrayList constructor used for review creates a separate list containing the element references from cart. Find the final sum of units across cart and the final sum across review. Report both totals in units as exact integers.
An immutable list containing mutable lamps
A lighting application executes this Scala 3 code. The head operation accesses the first element, and the :+ operation produces a list with an appended element. Which statements are true after all statements execute? Select every true statement.
Find the first matching ticket
A Java ticket system uses the following method to search an array. Each Ticket has an integer field code, and its constructor sets that field to the supplied value.
The array supplied to every call is initialized as follows:
Complete the table for three independent calls. Count a code comparison only when items[i].code == target is evaluated. Java evaluates the right side of && only when its left side is true. Give every answer as an exact integer.
Repack crates through an array parameter
A bottling workshop uses Java arrays of Crate objects. Each object has a mutable integer field bottles; new Crate(n) creates a distinct object whose field equals n.
The workshop defines this method:
The following fragment runs inside another method: