Parcel Total from a Traversal

A shipping program runs the following Java code with standard java.util imports. Each integer in masses is a parcel mass in kilograms, and the list remains unchanged.


Java
var masses = List.of(4, 7, 3, 8, 6, 5);
var scan = masses.iterator();
int total = 0;
while (scan.hasNext()) {
    scan.next();
    total += scan.next();
}


What is the final value of total, in kilograms? Enter an exact integer, with no decimal places.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Iterable and Iterator Questions: