Computer Applications

Write a program that computes the standard deviation of N real numbers. The standard deviation s is computed according to: The variable is the average of N input values through . The program first prompts the user for N and then declares an array of size N.

Java

Java Arrays

9 Likes

Answer

import java.util.Scanner;

public class KboatStdDev
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter N:");
        int n = in.nextInt();
        
        double a[] = new double[n];
        
        System.out.println("Enter the numbers:");
        for (int i = 0; i < n; i++) {
            a[i] = in.nextDouble();
        }
        
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }
        
        double avg = sum / n;
        double z = 0;
        for (int i = 0; i < n; i++) {
            z += Math.pow(a[i] - avg, 2);
        }
        
        double s = Math.sqrt(z / n);
        
        System.out.println("Standard Deviation(s) = " + s);
    }
}

Output

BlueJ output of Write a program that computes the standard deviation of N real numbers. The standard deviation s is computed according to: The variable is the average of N input values through . The program first prompts the user for N and then declares an array of size N.BlueJ output of Write a program that computes the standard deviation of N real numbers. The standard deviation s is computed according to: The variable is the average of N input values through . The program first prompts the user for N and then declares an array of size N.

Answered By

4 Likes


Related Questions