Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I get my code to display both outputs. It only displays sample 2 correctly but not sample 1. I need it to display

How can I get my code to display both outputs. It only displays sample 2 correctly but not sample 1. I need it to display both outputs at it is shown below.

Sample 1:

Enter numbers: 1 2 3 4.5 5.6 6 7 8 9 10

The mean is 5.61

The standard deviation is 2.99794

Sample 2:

Enter a number: 55

Enter a number: 60

Enter a number: 75.66

Enter a number: 81.2

Enter a number: 90.55

Enter a number: 100.1

Enter a number: 66.69

Enter a number: 75.5

Enter a number: 88.88

Enter a number: 99.99

The mean is 79.357

The standard deviation is 15.749124173179341

import java.util.Scanner;

import java.lang.*;

public class CAL_Mean_SD {

public static void main(String[] args) {

//variables

double sum = 0;

double std = 0;

//create a scanner object

Scanner in = new Scanner(System.in);

//create an array

double [] arr = new double[100];

//loop for 10 times

for(int i = 0; i<10; i++)

{

System.out.print("Enter a number: ");

arr[i] = in.nextDouble();

sum = sum + arr[i];

}

//calculating average

double avg = sum/10;

for(int i=0;i<10;i++)

{

//calculating total difference from the mean

std = std + Math.pow(arr[i] - avg, 2);

}

//calculating variance

double variance = std/9;

//calculating standard deviation

double standard_deviation = Math.sqrt(variance);

//Display Mean

System.out.println("The mean is " +avg);

//display Standard deviation

System.out.println("The Standard deviation is "+standard_deviation);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Explain the steps involved in planning a promotions approach.

Answered: 1 week ago

Question

3. Describe at least two features of wise reasoning.

Answered: 1 week ago