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.
static int indexOf(Ticket[] items, int target) { for (int i = 0; i < items.length; i++) { if (items[i] != null && items[i].code == target) { return i; } } return -1; }
The array supplied to every call is initialized as follows:
Ticket[] items = { new Ticket(17), new Ticket(58), null, new Ticket(41), new Ticket(58) };
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.
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.
Visit a shared box twice
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.
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: