Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Matthew Britt
- * Date: 11/20/2017
- * Course Number: CSC-111
- * Course Name: Introduction to Java Programming
- * Problem Number: 7.11
- * Email: msbritt0001@student.stcc.edu
- * Short Description of the Problem: Computes the standard deviation and the mean of 10 numbers.
- */
- import java.util.Scanner;
- public class ComputingDeviation {
- static final int SIZE = 10;
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double[] numbers = new double[SIZE];
- System.out.println("Enter " + SIZE + " numbers: ");
- for (int i = 0; i < numbers.length; i++)
- numbers[i] = input.nextDouble();
- System.out.println("The mean is: " + mean(numbers));
- System.out.println("The standard deviation is: " + deviation(numbers));
- }
- public static double mean(double[] x) {
- double total = 0;
- for (int i = 0; i < x.length; i++) {
- total += x[i];
- }
- System.out.println("Total: " + total);
- return total / x.length;
- }
- public static double deviation(double[] x) {
- double mean = mean(x);
- double deviation = 0;
- for (int i = 0; i < x.length; i++) {
- deviation += Math.pow(x[i] - mean, 2);
- }
- return Math.sqrt(deviation / (x.length - 1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement