java standard deviation
/*_x000D_
* Write an application that creates an int array of _x000D_
* size 1000000, assigns a random integer between + and _x000D_
* -10000 to each and computes the mean and _x000D_
* standard deviation as decimal values._x000D_
* Print those to the user._x000D_
* _x000D_
* Mean: _x000D_
* (sum of all values) / (number of values)_x000D_
* _x000D_
* Standard Deviation: _x000D_
* The square root of _x000D_
* the average of _x000D_
* the squared differences of _x000D_
* each value from the mean._x000D_
* _x000D_
*/_x000D_
_x000D_
public class StandardDeviation{_x000D_
public static void main(String[] args){_x000D_
_x000D_
int[] values = new int[1000000];_x000D_
final int MIN_VALUE = -10000;_x000D_
final int MAX_VALUE = 10000;_x000D_
double valuesSum = 0.0, sqDiffSum = 0.0, mean, standardDev;_x000D_
_x000D_
// Set each element in values equal to a random_x000D_
// integer between MIN_VALUE and MAX_VALUE_x000D_
_x000D_
_x000D_
// Compute the sum of all elements in values,_x000D_
// such the sum gets stored in valuesSum_x000D_
_x000D_
_x000D_
_x000D_
// Compute the mean (average) of all values_x000D_
// and store in the variable mean_x000D_
_x000D_
_x000D_
// Compute the sum of the squared differences_x000D_
// of each value from the mean. Conceptually,_x000D_
// this looks like:_x000D_
// (first - mean)^2 + _x000D_
// (second - mean)^2 + _x000D_
// (third - mean)^2 + _x000D_
// ....... +_x000D_
// (last - mean)^2 + _x000D_
_x000D_
_x000D_
_x000D_
_x000D_
// Compute the standard deviation, which is the _x000D_
// square root of the result of dividing the sum of _x000D_
// squared differences by the total number of values_x000D_
_x000D_
_x000D_
_x000D_
System.out.println("Mean: " + mean);_x000D_
System.out.println("Standard Deviation: " + standardDev);_x000D_
_x000D_
}_x000D_
_x000D_
private static int randomIntInRange(int low, int high) {_x000D_
_x000D_
int multiplier = high - (low - 1);_x000D_
return (int)(Math.random() * multiplier) + low;_x000D_
_x000D_
}_x000D_
_x000D_
}
output
Mean: -3.77569_x000D_ Standard Deviation: 5779.955079273639
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


