473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Population Standard Deviation - java

1
Hello!

So i am a new programmer and i really need some help. I am trying to find the Population Standard Deviation of 7 numbers which the user inputs.

Please see below my

Expand|Select|Wrap|Line Numbers
  1.         double dayOne, dayTwo, dayThree, dayFour, dayFive, daySix, daySeven, avgRain = 0, stanDeviation = 0, dayOneSq = 0, dayTwoSq, dayThreeSq, dayFourSq, dayFiveSq, daySixSq, daySevenSq, avgRainSq; 
  2.  
  3.  
  4.         //Get rainfall information from users.
  5.  
  6.         System.out.println("Enter rainfall measurement for Day 1 (in mm): ");
  7.         dayOne = reader.nextDouble();
  8.  
  9.         System.out.println("Enter rainfall measurement for Day 2 (in mm): ");
  10.         dayTwo = reader.nextDouble();
  11.  
  12. Etc, Etc.
  13.  
  14.      //find average
  15.  
  16. avgRain = (dayOne + dayTwo + dayThree + dayFour + dayFive + daySix + daySeven)/7;
  17.  
  18.      // calculate population deviation
  19.  
  20.         dayOneSq = (dayOne - avgRain);
  21.               Math.pow(2,dayOneSq);
  22.  
  23.         dayTwoSq = (dayTwo - avgRain);
  24.             Math.pow(2,dayTwoSq);
  25.  
  26.         etc..etc...
  27.  
  28.         //find standard deviation
  29.  
  30.         avgRainSq = (dayOneSq + dayTwoSq + dayThreeSq + dayFourSq + dayFiveSq
  31.                         + daySevenSq)/7;
  32.  
  33.         stanDeviation = (Math.sqrt(avgRainSq));
  34.  
  35.  
  36. System.out.printf (", Standard Deviation: %.4f\n\n",stanDeviation);
any hint would be fantastic!! Thanks!!!
Aug 5 '13 #1
2 2251
chaarmann
785 Expert 512MB
Please correct your post and use code tag to format your code.
You forgot to mention your problem. What did not work in a way you expected?

Tip:
You can reduce your code size by using arrays (or Lists) and for-loops: You should not use double day1, day2, day3 etc., but "double[] days = new double[7]" and access for example day 3 by "days[2]" ,or using a loop "for(int i=0; i < 7; i++){...}" with "day[i]"
Aug 5 '13 #2
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

You never assign the result of math.pow to anything. So you end up never having your squared differences. Also, your arguments need to be reversed, it's the first argument to the power of the second argument, not the reverse.
Aug 5 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: T.Venkatesh | last post by:
Hi friends, I just got stuck up in JDBC,JSP. My problem is iam unable to display the output of Standard deviation , variance sum, of a column in a JSP page. But it complies- but no display of...
3
by: mat | last post by:
Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai écrite. Si ça peut servir à d'autres ... echo "Calcul d'un ecart type"; echo "<br>"; $datas =...
3
by: Scott | last post by:
I know in some other languages there is a simple standard deviation function (sdev(1,2,3,4,5,etc...)). But I'm unable to find a suitable alternative for vb.net I'm assuming it's there...
2
by: Quentin | last post by:
How would I calculate standard deviation of a csv file? Any code examples would be great! Thank you!
10
by: Verbal Kint | last post by:
DEAR ALL, I just have a very short question. In the FAQ list question 13.20 the following text is mentioned: "These methods all generate numbers with mean 0 and standard deviation 1. (To adjust...
0
by: aboxylica | last post by:
do v have a function to calculate variance, average and standard deviation in python??
6
by: kumarboston | last post by:
Hi All, I am trying to get an average value for my data, here is my data file DATA FILE EP1934.PDB 250 250 11.27 EP1934.PDB 251 251 12.7332 EP1934.PDB 252 252 6.38341 EP1934.PDB 253 253...
6
by: shibujohn82 | last post by:
Hi, My data set is followed like this... (as tab delimited input.csv) First is column is gene name, second column is bn count, third colums is sh count. ENSRNOG00000000417 42 102...
3
by: yawsam | last post by:
How can i use aggregate function like count, sum and other to calculate standard deviation in SQL
0
by: Dave Smith | last post by:
I’m hoping someone can help me with my newest rank issue. I’m trying to get a rank my standard deviation so it will be a number below 1, the numbers I'm trying to rank are below. Example: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.