Didart

Academy Graduation

Jan 19th, 2023 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package SetsAndMaps;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6. import java.util.TreeMap;
  7.  
  8. public class AcademyGraduation {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         int number = Integer.parseInt(scanner.nextLine());
  13.  
  14.         Map<String, Double> students = new TreeMap<>();
  15.  
  16.         for (int index = 0; index < number; index++) {
  17.             String studentName = scanner.nextLine();
  18.             double[] scores = Arrays
  19.                     .stream(scanner.nextLine().split("\\s+"))
  20.                     .mapToDouble(Double::parseDouble)
  21.                     .toArray();
  22.             double averageScore = 0.0;
  23.            
  24.             for (double score : scores) {
  25.                 averageScore += score;
  26.             }
  27.             averageScore /= scores.length;
  28.             students.putIfAbsent(studentName,averageScore);
  29.         }
  30.         students.forEach((key, value) -> {
  31.             System.out.printf("%s is graduated with " + value + "%n", key);
  32.         });
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment