Question

In: Computer Science

Find the Standard Deviation in Java: Use Arrays and Looping. Calculate the Standard Deviation once you...

Find the Standard Deviation in Java: Use Arrays and Looping. Calculate the Standard Deviation once you have the m numbers in an Array of size m. *Don't use different methods

Solutions

Expert Solution

import java.util.Scanner;

public class TestCode {
    public static void main(String args[]){
        int n;
        Scanner scanner = new Scanner(System.in);
        System.out.print("How many input numbers: ");
        n = scanner.nextInt();

        double arr[] =  new double[n];
        System.out.print("Enter "+ n +" numbers: ");
        for(int i = 0;i<n;i++){
            arr[i] = scanner.nextDouble();
        }

        double sum = 0;
        for(int i = 0;i<n;i++){
            sum += arr[i];
        }
        double mean = sum/n;

        double res = 0;
        for(int i = 0;i<n;i++){
            res += Math.pow(arr[i]-mean,2);
        }
        res = (float) Math.sqrt(res/ (n-1));
        System.out.println("Standard deviation: "+ res);
    }
}


Related Solutions

JAVA I need to write a code that calculates mean and standard deviation using arrays and...
JAVA I need to write a code that calculates mean and standard deviation using arrays and OOP. This is what I have so far. I'm close but my deviation calculator method is throwing errors. Thanks so much :) import java.util.Scanner; import java.util.Arrays; public class STDMeanArray { private double[] tenUserNums = new double[10];//Initialize an array with ten index' private double mean; private double deviation; Scanner input = new Scanner(System.in);//create new scanner object /*//constructor public STDMeanArray(double tenUserNum [], double mean, double deviation){...
Use the following information to calculate the expected return and standard deviation of a portfolio that...
Use the following information to calculate the expected return and standard deviation of a portfolio that is 30 percent invested in 3 Doors, Inc., and 70 percent invested in Down Co. 3 Doors, Inc Down Co Expected Return, E(R) 18% 14% Standard deviation 48 50 Correlation .33
Use the following information to calculate the expected return and standard deviation of a portfolio that...
Use the following information to calculate the expected return and standard deviation of a portfolio that is 50 percent invested in 3 Doors, Inc., and 50 percent invested in Down Co.: (Do not round intermediate calculations. Enter your answers as a percent rounded to 2 decimal places.) 3 Doors, Inc. Down Co. Expected return, E(R) 14 % 10 % Standard deviation, σ 42 31 Correlation 0.10
(a) Use the Sample Variance Definition to find the variance and standard deviation of the data.
Perform each task, given the following sample data. (Round your answers to one decimal place.) 4 8 7 4 10 9 (a) Use the Sample Variance Definition to find the variance and standard deviation of the data. variance     standard deviation     (b) Use the Alternative Formula for Sample Variance to find the variance and standard deviation of the data. variance     standard deviation    
You are to calculate the mean and standard deviation for the rate of returns for IBM...
You are to calculate the mean and standard deviation for the rate of returns for IBM and GE. Use monthly values for the period August 1, 2007 through August 1, 2018 Q10.You are to calculate the mean and standard deviation for the rate of returns for IBM and GE. Use monthly values for the periodAugust 1, 2007 through August 1, 2018. Data can be obtained from the WWW as follows 1.Go to http:www.yahoo.com. Select the Finance option 2.Enter your stock's...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You...
Java Prorgramming Skills Looping Branching Use of the length(), indexOf(), and charAt() methods of class String...
Java Prorgramming Skills Looping Branching Use of the length(), indexOf(), and charAt() methods of class String Use of the static Integer.toHexString method to convert a character to its ASCII hex value Description In this assignment, you'll be URL encoding of a line of text. Web browsers URL encode certain values when sending information in requests to web servers (URL stands for Uniform Resource Locator). Your program needs to perform the following steps: Prompt for a line of input to be...
Use the indicated margin of error, the confidence level, and the population standard deviation to calculate...
Use the indicated margin of error, the confidence level, and the population standard deviation to calculate the minimum sample size required to estimate an unknown population mean. a) Error margin: 0.5 inch, confidence level: 95%, Standard deviation: 2.5 inch. b) margin of error: 0.25 seconds, confidence level: 99%, standard deviation: 5.4 seconds. c) Margin of error: $ 1, confidence level: 99%, standard deviation: $ 12. d) Margin of error: 1.5 mm, confidence level: 95%, standard deviation: 8.7 mm
Do you find it intuitive, or not, that the mean and standard deviation of a sampling...
Do you find it intuitive, or not, that the mean and standard deviation of a sampling distribution aren't impacted by population size? Explain to a friend who hasn't taken statistics what a sampling distribution is, and what makes them useful. What questions can they help us answer, and what information is required?
Use Descriptive Statistics in Excel to find the mean, median, range and standard deviation of the...
Use Descriptive Statistics in Excel to find the mean, median, range and standard deviation of the data below. Table 1: Health Expenditures as a Percentage of GDP of countries around the world 3.35 5.96 10.64 5.24 3.79 5.65 7.66 7.38 5.87 11.15 5.96 4.78 7.75 2.72 9.50 7.69 10.05 11.96 8.18 6.74 5.89 6.20 5.98 8.83 6.78 6.66 9.45 5.41 5.16 8.55
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT