The sum() method belongs to the concrete value members of the class AbstractIterator. It is defined in the classes TraversableOnce and GenTraversableOnce. It adds the elements of the stated collection.
def sum: A
It returns the sum of all the elements in the stated iterator.
Here, the sum of all the elements is printed.