Challenge: Score Report

Lab Java Intermediate 20 points

Read n scores. Using streams, print how many scores are 50 or more, the highest score, and the average with 1 decimal.

Input

First n (n ≥ 1), then n whole numbers.

Output

Passed: <count>
Highest: <max>
Average: <avg, 1 decimal>

Example

Input

5
78 92 45 60 30

Output

Passed: 3
Highest: 92
Average: 61.0
Sample input available Sample output available
Editor
Java

Hints

count() gives a long.

mapToInt(x -> x) gives an IntStream with max() and average().

average() returns an OptionalDouble – call getAsDouble().

Solution explanation

Each line is a small stream: filter-and-count, then max, then average.

Show solution
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> s = new ArrayList<>();
        for (int i = 0; i < n; i++) s.add(sc.nextInt());
        System.out.println("Passed: " + s.stream().filter(x -> x >= 50).count());
        System.out.println("Highest: " + s.stream().mapToInt(x -> x).max().getAsInt());
        System.out.printf("Average: %.1f%n", s.stream().mapToInt(x -> x).average().getAsDouble());
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD