Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /*
  2. * Name: Matthew Britt
  3. * Date: 11/20/2017
  4. * Course Number: CSC-111
  5. * Course Name: Introduction to Java Programming
  6. * Problem Number: 7.11
  7. * Email: msbritt0001@student.stcc.edu
  8. * Short Description of the Problem: Computes the standard deviation and the mean of 10 numbers.
  9. */
  10. import java.util.Scanner;
  11.  
  12. public class ComputingDeviation {
  13.  
  14. static final int SIZE = 10;
  15.  
  16. public static void main(String[] args) {
  17. Scanner input = new Scanner(System.in);
  18. double[] numbers = new double[SIZE];
  19. System.out.println("Enter " + SIZE + " numbers: ");
  20. for (int i = 0; i < numbers.length; i++)
  21. numbers[i] = input.nextDouble();
  22. System.out.println("The mean is: " + mean(numbers));
  23. System.out.println("The standard deviation is: " + deviation(numbers));
  24.  
  25. }
  26.  
  27. public static double mean(double[] x) {
  28. double total = 0;
  29. for (int i = 0; i < x.length; i++) {
  30. total += x[i];
  31. }
  32. System.out.println("Total: " + total);
  33. return total / x.length;
  34.  
  35. }
  36.  
  37. public static double deviation(double[] x) {
  38. double mean = mean(x);
  39. double deviation = 0;
  40. for (int i = 0; i < x.length; i++) {
  41. deviation += Math.pow(x[i] - mean, 2);
  42. }
  43. return Math.sqrt(deviation / (x.length - 1));
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement