java standard deviation

May 3rd, 2015
KateS
Category:
Programming
Price: $5 USD

Question description

/*
 * Write an application that creates an int array of 
 * size 1000000, assigns a random integer between + and 
 * -10000 to each and computes the mean and 
 * standard deviation as decimal values.
 * Print those to the user.
 * 
 * Mean: 
 * (sum of all values) / (number of values)
 * 
 * Standard Deviation: 
 * The square root of 
 *    the average of 
 *      the squared differences of 
 *         each value from the mean.
 * 
 */

public class StandardDeviation{
  public static void main(String[] args){
    
    int[] values = new int[1000000];
    final int MIN_VALUE = -10000;
    final int MAX_VALUE = 10000;
    double valuesSum = 0.0, sqDiffSum = 0.0, mean, standardDev;
    
    // Set each element in values equal to a random
    // integer between MIN_VALUE and MAX_VALUE
    
    
    // Compute the sum of all elements in values,
    // such the sum gets stored in valuesSum
    
    
    
    // Compute the mean (average) of all values
    // and store in the variable mean

    
    // Compute the sum of the squared differences
    // of each value from the mean.  Conceptually,
    // this looks like:
    //    (first - mean)^2 + 
    //    (second - mean)^2 + 
    //    (third - mean)^2 + 
    //    ....... +
    //    (last - mean)^2 + 
    
    
    
    
    // Compute the standard deviation, which is the 
    // square root of the result of dividing the sum of 
    // squared differences by the total number of values

    
    
    System.out.println("Mean:               " + mean);
    System.out.println("Standard Deviation: " + standardDev);
    
  }
  
  private static int randomIntInRange(int low, int high) {
    
    int multiplier = high - (low - 1);
    return (int)(Math.random() * multiplier) + low;
    
  }
  
}
output

Mean:               -3.77569
Standard Deviation: 5779.955079273639

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: UIUC
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
Five Star Tutor
Dec 4th, 2016
" Outstanding Job!!!! "
SjSurvivor143
Nov 18th, 2016
" Thanks for the help. "
Joemoe
Nov 5th, 2016
" <3 it, thanks for saving me time. "
tinytim47
Oct 27th, 2016
" Wow this is really good.... didn't expect it. Sweet!!!! "
pmallory
Oct 22nd, 2016
" Totally impressed with results!! :-) "
mixedballz
Oct 13th, 2016
" excellent work as always thanks for the help "
kiln82
Sep 30th, 2016
" awesome work thanks "
darnay
Sep 21st, 2016
" The best tutor out there!!!! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1821 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors