Guest User

Untitled

a guest
Feb 24th, 2020
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.lang.reflect.Array;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.Collections;
  5. import java.util.Scanner;
  6.  
  7. public class AvgStandardDeviation
  8. {
  9. public static void main(String[] args)
  10. {
  11. Scanner in = new Scanner(System.in);
  12. System.out.println("Моля въведи брой състезатели");
  13. int numberOfContestants = in.nextInt();
  14. System.out.println("Моля въведи поотделно времената на спринтиране на състезателите");
  15. ArrayList<Double> timesOfContestants = new ArrayList<>();
  16.  
  17. int sum = 0;
  18. double avg;
  19. for (int i = 0; i < numberOfContestants ; i++) {
  20. timesOfContestants.add(in.nextDouble());
  21. Collections.sort(timesOfContestants);
  22. sum += timesOfContestants.get(i);
  23. }
  24. avg = sum/timesOfContestants.size();
  25. double squaredDifference;
  26. double standardDeviation;
  27. double sumSquaredDifference = 0;
  28.  
  29. for (double time: timesOfContestants
  30. ) {
  31. squaredDifference = Math.pow((time-avg), 2);
  32. sumSquaredDifference +=squaredDifference;
  33. }
  34. standardDeviation = Math.sqrt(sumSquaredDifference/timesOfContestants.size());
  35. System.out.println(timesOfContestants);
  36. System.out.println("Най-бърз"+ ": " + timesOfContestants.get(0));
  37. System.out.println("Най-бавен"+ ": " + timesOfContestants.get(timesOfContestants.size() -1));
  38. System.out.println("Avg"+ ": " + avg);
  39. System.out.println("standardDeviation = " + standardDeviation);
  40.  
  41. }
  42. }
RAW Paste Data