Advertisement
nikeza

Academy Graduation /Map to double[]/

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