Question 18
Back to Exercise
What is the output of the following Java program?
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] temps = {31, 29, 35, 33, 28, 30};
System.out.println(Arrays.stream(temps).max().getAsInt() + " " + Arrays.stream(temps).min().getAsInt() + " "
+ Arrays.stream(temps).sum() + " " + Arrays.stream(temps).average().getAsDouble() + " "
+ Arrays.stream(temps).filter(t -> t > 30).count());
}
}
- A 35 28 186 31.0 3 Correct
- B 35 28 186 31 3
- C 35 29 186 31.0 2
- D 35 28 180 30.0 3
Correct Answer: Option A
IntStream offers max, min, sum, average and count; average returns a double.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!