Advertisement
nikeza

8.Academy Graduation

Sep 29th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class map1_Lab_8Academy_Graduation {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         Map<String, List<Double>> academy = new TreeMap<>();
  10.         for (int i = 0; i < n; i++) {
  11.             String name = scanner.nextLine();
  12.             List<Double> grade = Arrays.stream(scanner.nextLine().split("\\s+"))
  13.                     .map(Double::parseDouble)
  14.                     .collect(Collectors.toList());
  15.                    
  16.             academy.putIfAbsent(name, grade);
  17.         }
  18.  
  19.         for (Map.Entry<String, List<Double>> entry : academy.entrySet()) {
  20.  
  21.             System.out.printf("%s is graduated with ", entry.getKey());
  22.             double avg = 0;
  23.             for (Double value : entry.getValue()) {
  24.                 avg += value;
  25.             }
  26.             System.out.println(avg / entry.getValue().size());
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement