Advertisement
GeorgiStGeorgiev

Untitled

Feb 24th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Deviation {
  5. public static void main(String[] args) {
  6. int participants;
  7. double [] arrSeconds = new double[10] ;
  8. int i = 0;
  9. double fastest = 50000 ;
  10. double slowest =0;
  11. Scanner scan = new Scanner(System.in);
  12. System.out.print("Брой на участниците :");
  13. participants = scan.nextInt();
  14. if( participants > 10){
  15. System.out.print("Моля въведете до 10 участника. Въведете наново :");
  16. participants = scan.nextInt();
  17. }
  18. while (i < participants){
  19. System.out.print("Участник номер " + i + " секунди :");
  20. arrSeconds[i]= scan.nextDouble();
  21. i++;
  22. }
  23. System.out.println(Arrays.toString(arrSeconds));
  24. double total = 0;
  25. for( int j = 0 ; j <participants ; j++){
  26. if(arrSeconds[j]>slowest){
  27. slowest = arrSeconds[j];
  28. }
  29. if(arrSeconds[j]<fastest && arrSeconds[j]!=0){
  30. fastest = arrSeconds[j];
  31. }
  32. total +=arrSeconds[j];
  33. }
  34. double averageSeconds = total/participants;
  35. System.out.println("Най-бързо време : " + fastest);
  36. System.out.println("Най-бавно време : " + slowest);
  37. System.out.println("Средно Аретм. : " + averageSeconds);
  38. double mean = total/participants;
  39. double preVariance =0 ;
  40. for (int j =0 ; j < participants; j++){
  41. preVariance+=Math.pow(arrSeconds[j] - mean , 2);
  42. }
  43. double variance= preVariance/(participants -1);
  44. double standartDeviation = Math.sqrt(variance);
  45. System.out.println("Standart Deviation : " + standartDeviation);
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement