Question

Please help! We use Java JGrasp. Write a Java program to take the input of 5...

Please help! We use Java JGrasp.

Write a Java program to take the input of 5 numbers and output the mean (average) and standard deviation of the numbers.

If the numbers are x1, x2, x3, x4, and x5, the formula for mean is

X = (x1 + x2 + x3 + x4 + x5)/5

And the formula for standard deviation is

You can also break standard deviation down like this:

1. Work out the Mean (the simple average of the numbers)

2. Then for each number: subtract the Mean and square the result

3. Then work out the mean of those squared differences.

4. Take the square root of that and we are done!

What you need to do for this lab: • Doubles will be better to use than integers. • You will need to create a method to calculate the mean and a method to calculate the standard deviation. • Use the Math.sqrt method to use squareroot.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MeanSDTest.java

import java.util.Scanner;

public class MeanSDTest {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the 5 numbers:");

double x1= scan.nextDouble();

double x2= scan.nextDouble();

double x3= scan.nextDouble();

double x4= scan.nextDouble();

double x5= scan.nextDouble();

double mean = getMean(x1, x2, x3, x4, x5);

System.out.println("Mean: "+mean);

System.out.println("Standard Deviation: "+getStandardDeviation(mean, x1, x2, x3, x4, x5));

}

public static double getMean(double x1, double x2, double x3, double x4, double x5) {

return (x1 + x2 + x3 + x4 + x5) / 5;

}

public static double getStandardDeviation(double mean, double x1, double x2, double x3, double x4, double x5) {

double standardDeviation = 0;

standardDeviation += Math.pow(x1 - mean, 2);

standardDeviation += Math.pow(x2 - mean, 2);

standardDeviation += Math.pow(x3 - mean, 2);

standardDeviation += Math.pow(x4 - mean, 2);

standardDeviation += Math.pow(x5 - mean, 2);

standardDeviation= Math.sqrt(standardDeviation);

return standardDeviation;

}

}

Output:

Enter the 5 numbers:
3
4
5
6
7
Mean: 5.0
Standard Deviation: 3.1622776601683795

Add a comment
Know the answer?
Add Answer to:
Please help! We use Java JGrasp. Write a Java program to take the input of 5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT