Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class map1_Lab_5Average_Students_Grades {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- Map<String, List<Double>> students = new TreeMap<>();
- for (int i = 0; i < n; i++) {
- String[] input = scanner.nextLine().split("\\s+");
- double grade = Double.parseDouble(input[1]);
- students.putIfAbsent(input[0], new ArrayList<>());
- students.get(input[0]).add(grade);
- }
- for (Map.Entry<String, List<Double>> entry : students.entrySet()) {
- System.out.print(entry.getKey() + " -> ");
- double avg = 0;
- for (Double s : entry.getValue()) {
- System.out.printf("%.2f ", s);
- avg += s;
- }
- // double avg = entry.getValue().stream()
- // .mapToDouble(Double::doubleValue)
- // .average()
- // .getAsDouble();
- System.out.printf("(avg: %.2f)%n", avg / entry.getValue().size());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement