# Mean and Standard Deviation?

Page 1 of 1

## 3 Replies - 4608 Views - Last Post: 27 October 2011 - 09:34 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=253223&amp;s=63d02f7562d0709ce408cf5ca728be9e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Epic800

Reputation: 0
• 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

• Games, Graphs, and Auctions

Reputation: 11136
• Posts: 41,835
• 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!

### #3 Epic800

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

## Re: Mean and Standard Deviation?

Posted 27 October 2011 - 09:31 PM

macosxnerd101, 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?

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11136
• Posts: 41,835
• 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();
}

```