3 Replies - 4094 Views - Last Post: 27 October 2011 - 09:34 PM Rate Topic: -----

#1 Epic800  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 28-August 11

Mean and Standard Deviation?

Posted 27 October 2011 - 09:20 PM

I am trying a write a program where you enter 10 numbers and it outputs the mean and standard deviation?

I have this so far...

I believe I have the correct formulation for the mean. I am unsure on how to calculate standard deviation.


import java.util.Scanner;
public class Exercise05_21 {
    public static void main(String[] args) {
    
      Scanner input = new Scanner(System.in);
       
     System.out.print("x1:");
      int x1 = input.nextInt();
      System.out.print("x2:");
      int x2 = input.nextInt();
       System.out.print("x3:");  
      int x3 = input.nextInt();
      System.out.print("x4:");
      int x4 = input.nextInt();
      System.out.print("x5:");
      int x5 = input.nextInt();
      System.out.print("x6:");
      int x6 = input.nextInt();
      System.out.print("x7:");
      int x7 = input.nextInt();
      System.out.print("x8:");
      int x8 = input.nextInt();
     System.out.print("x9:");
     int x9 = input.nextInt();
      System.out.print("x10:");
     int x10 = input.nextInt();
  
    }
      
      public int mean(int x1,int x2,int x3,int x4,int x5,int x6,int x7,int x8,int x9,int x10) {
          
          int n = 10;
          
          int mean;
          
         mean = (x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10) / n;
    
       return mean;
    
      }
}


This post has been edited by Epic800: 27 October 2011 - 09:30 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Mean and Standard Deviation?

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10767
  • View blog
  • Posts: 40,094
  • Joined: 27-December 08

Re: Mean and Standard Deviation?

Posted 27 October 2011 - 09:28 PM

Please- use an array here. Also, you have 44 posts. You know that in order for us to help you, that you must ask specific questions and describe your problems specifically!
Was This Post Helpful? 0
  • +
  • -

#3 Epic800  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 28-August 11

Re: Mean and Standard Deviation?

Posted 27 October 2011 - 09:31 PM

View Postmacosxnerd101, on 27 October 2011 - 09:28 PM, said:

Please- use an array here. Also, you have 44 posts. You know that in order for us to help you, that you must ask specific questions and describe your problems specifically!


Sorry about that, I have edited my original post. In my class we have yet learned arrays. If you desire, could you elaborate?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10767
  • View blog
  • Posts: 40,094
  • Joined: 27-December 08

Re: Mean and Standard Deviation?

Posted 27 October 2011 - 09:34 PM

You really just couldn't do a Google search for the standard deviation formula? First result- http://en.wikipedia....ndard_deviation

If you know you have ten elements, just create an int[] to store ten elements.
int[] values = new int[10]; 



An array is like having a bunch of variables you can refer to under a single name and number, we'll call an index. So cookie1, cookie2, cookie3, etc., do not allow you to loop through them. Arrays allow you to loop through them.

for(int i = 0; i < values.length; i++){
    System.out.println("Enter value: " + i);
    values[i] = scan.nextInt();
    scan.nextLine();
}



More supplemental reading on arrays:
http://www.dreaminco...tion-to-arrays/
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1