Advertisement
Guest User

AcademyGraduation

a guest
Feb 2nd, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.*;
  3.  
  4. public class AcademyGraduation {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         Map<String, Double[]> students = new TreeMap<>();
  9.  
  10.         int n = Integer.parseInt(scanner.nextLine());
  11.  
  12.         for (int i = 0; i < n; i++) {
  13.             String name = scanner.nextLine();
  14.             String[] arr = scanner.nextLine().split("\\s+");
  15.  
  16.  
  17.             Double[] scores = new Double[arr.length];
  18.  
  19.             for (int j = 0; j < arr.length; j++) {
  20.                 scores[j] = Double.parseDouble(arr[j]);
  21.             }
  22.  
  23.             students.put(name, scores);
  24.         }
  25.  
  26.         students.forEach((k, v) -> {
  27.             System.out.print(k + " is graduated with ");
  28.              double sum = 0;
  29.             for (Double aDouble : v) {
  30.                 sum += aDouble;
  31.             }
  32.             double average = sum / v.length;
  33.             DecimalFormat floatPoint;
  34.             floatPoint = new DecimalFormat("#.###############");
  35.             System.out.println(floatPoint.format(average));
  36.         });
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement