• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

standard deviation of any sized array java

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys I'm having trouble figuring out how to calculate the standard divination of an array in Java. As you can see I have already calculated the mean, and I know that at the end I will have to divide by the sample size minus 1 (n-1) and square that number. The problem I'm having is how to take every number and calculate how far it is away from the mean, then square that number. I know I could do every number from the data set separately but there has to be an easier way. Any help would be appreciated, here's my code.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your problem that you don't know what is meant by "how far it is away from the mean"? You'd take the number and subtract the mean, that's how. (Calling the variable which stores the mean value "average" wasn't a good choice, by the way.)

And yes, you do have to do that for each data point in the sample. So putting it inside the loop like you did, you're on the right track.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is probably a package you can download that would have everything you need in it, but I'm guessing you are supposed to do this yourself.

The first steps when writing a program should always be to think through how you'd do it yourself, with pencil and paper. In order to figure out how far a number is from the mean, you need two things: the number, and the mean.

And you can't get the mean until you have looked at every number.

So yes, you do need to loop through your array (at least) twice. Once to get the mean, and once to get the difference between each number and the mean. There is no way to do it in one pass.
reply
    Bookmark Topic Watch Topic
  • New Topic