Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started