Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 153

Given the code fragment:

Which should be inserted into line n1 to print Average = 2.5?

    Correct Answer: B

    To print the average of the numbers 1, 2, 3, and 4, which equals 2.5, the correct stream type used should be an IntStream. The method average() is available in IntStream and it returns an OptionalDouble, from which the getAsDouble() method can be called to get the actual double value. The appropriate declaration to achieve this is 'IntStream str = IntStream.of(1, 2, 3, 4);'. Using DoubleStream or Stream would not work correctly with the available methods.

Discussion
ChirajOption: B

The answer is B.

Abdullah_RahahleahOption: B

answer is B-tested

DarGrinOption: C

Answer is C. Stream.of() gives Stream<Integer> or Stream<Double>, not IntStream or DoubleStream. So A and C are incorrect. And Stream hat no method average(). So D is incorrect too.

asdfjhfgjuaDCVOption: B

B is the answer

steefaandOption: B

B is correct.

iSnoverOption: B

The answer is letter b, it cannot be C using the method in the second line "getAsDouble()".