1. Member
Join Date
Nov 2012
Posts
1
Rep Power
0

## Standard deviation project

Write a program to input up to 100 percentage scores and output 'A', 'B', 'C', 'D' or 'F' based on the standard deviation. A is 1˝ standard deviations above the mean and better, B is ˝ standard deviations above to 1˝ standard deviations above the mean, C is anything from ˝ a standard deviation above the mean to ˝ a standard deviation below, D is 1˝ standard deviations below the mean to ˝ a standard deviation below the mean, and F is more than 1˝ standard deviations below the mean. Enter a negative grade to quit.

this is what I have so far any help would be greatly appreciated.

I am hung up trying to make a loop so that it will only calculate with positive answers and when a negative is inserted it will stop.

Java Code:
``` import java.util.*;

public class StandardDeviation{
public double findMean(int array[]){
double total = 0;
for(int i = 0; i < array.length; i++){
total = total + array[i];
}
double mean = total/array.length;
return mean;
}
public void findStandardDeviation(int array[]){
double mean = findMean(array);
System.out.println("Mean is: "+mean);
double d1 = 0;
double d2 = 0;
double sum = 0;
for(int i = 0; i < array.length; i++){
d2 = (mean - array[i])*(mean - array[i]);
d1 = d2 + d1;
}
System.out.println("Standard Deviation: " + Math.sqrt((d1/(array.length-1))));
}

public static void main(String args[]){
Scanner input =new Scanner(System.in);

System.out.println("Enter Array Elements: ");
int array[] = new int[100];
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();

}
StandardDeviation sd = new StandardDeviation();
sd.findStandardDeviation(array);

}
}```

2. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15

## Re: Standard deviation project

I am hung up trying to make a loop so that it will only calculate with positive answers and when a negative is inserted it will stop.
The simple answer is that you can use an if statement to check what was entered and, if it is negative, then break out of the loop.

Notice, though, that the array will contain a whole bunch of zeros at the end. And this is no good because zero is a valid data value. So what you are going to have to do is fill these unused array slots with some negative value.

Even once you have done that array.length has nothing to do with the number of scores that were entered. Again because of the unused slots at the end. You may find yourself having to implement a findCount() method in the StandardDeviation class so that the other two methods can use this value. (There is also a straight forward way of calculating the standard deviation with "one sweep" through the data - which is how calculators do it, for instance - which you might want to investigate.)

3. ## Re: Standard deviation project

Originally Posted by pbrockway2
(There is also a straight forward way of calculating the standard deviation with "one sweep" through the data - which is how calculators do it, for instance - which you might want to investigate.)
... and those old calculators don't even have enough memory for huge arrays, so they don't use them ...

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•