## Flukeshot's Profile User Rating:

Reputation: 402 Architect
Group:
Contributors
Active Posts:
1,001 (1.92 per day)
Joined:
14-November 12
Profile Views:
8,791
Last Active:
Yesterday, 05:14 PM
Currently:
Offline

### Previous Fields

Country:
GB
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Honda
Dream Kudos:
50

### Latest Visitors

Flukeshot is back to relatively high activity

1. #### In Topic: program works until i type yes in order to loop, thats the problem.

Posted 17 Apr 2014

Notice line 11.
```while(repeat.equalsIgnoreCase(repeat))
```

repeat is always going to equal repeat if it's the very same line.
2. #### In Topic: How do i reference an input into another method?

Posted 17 Apr 2014

Because you're reporting the square root of the standard deviation. Try to understand the example, not just in terms of maths, but in fundamentals of Java and programming.

My mistake, I forgot to calculate the average of the sum before giving it to the square root method!

Here's the revised method and I'll edit the previous post.

```public static double standard(double[] x) {
double average = mean(x);
double sum = 0;
for (int i = 0; i < x.length; i++) {
x[i] = x[i] - average;
x[i] *= x[i];
sum += x[i];

//System.out.println(sum);
}
return Math.sqrt(sum/x.length);
}
```
3. #### In Topic: How do i reference an input into another method?

Posted 17 Apr 2014

The reason why it's not printing is hidden in this block of code:
```System.out.println("The mean is " + mean(numbers)); // this line is correct
System.out.println("The standard deviation is "); // this line has no method call
mean(numbers); // this line is redundant
```
4. #### In Topic: How do i reference an input into another method?

Posted 17 Apr 2014

To find the standard deviation of your collection, we must first find the mean (we already did so in our previous assignment).
```public double standardDeviation(double[] x) {
double average = mean(x); // let's get a clear reference to the average
}
```

Once we have the average, we can calculate the difference each point has from the average.
```public double standardDeviation(double[] x) {
double average = mean(x);
for(int i = 0; i < x.length; i++) {
x[i] = x[i] - average; // find the difference
}
}
```

Those results must be squared now.
```public double standardDeviation(double[] x) {
double average = mean(x);
for(int i = 0; i < x.length; i++) {
x[i] = x[i] - average;
x[i] *= x[i]; // square this value
}
}
```

Then we need to find the average from those values.
```public double standardDeviation(double[] x) {
double average = mean(x);
double sum = 0; // initialise our accumulator
for(int i = 0; i < x.length; i++) {
x[i] = x[i] - average;
x[i] *= x[i];
sum += x[i]; // add this processed value to the sum
}
}
```

It should start to appear clear to you at this moment, the final step is to find the square root with that utility method from the Math class!
```public double standardDeviation(double[] x) {
double average = mean(x);
double sum = 0;
for(int i = 0; i < x.length; i++) {
x[i] = x[i] - average;
x[i] *= x[i];
sum += x[i];
}
return Math.sqrt(sum/x.length); // this will give you the standard deviation
}
```
5. #### In Topic: How do i reference an input into another method?

Posted 17 Apr 2014

You're referencing it in correctly, but you're not using it.

```public static double mean(double[] x) { // the local variable here (double[] x) is equivilant to your passed array
double sum = 0; // this is the correct use of an accumulator
for (int i = 0; i < x.length; i++) { // ammended. use your local variable!
sum += x[i]; // as above, use your local variable
}
return sum; // we are returning the sum of all the values.. but aren't we looking for the mean?

// should be:
return sum / x.length;
}

```

Finally, your call to this method has a slight misconception. A method call with a return statement is equivilant to the value returned!

For example if a method private int returnNumber(int number) { return number; } was called in another method like this: int i = returnNumber(12); - This is equivilant to int i = 12;.

So use the following syntax:
```System.out.println("The mean is " + mean(numbers));
```

### My Information

Member Title:
A little too OCD
Age:
25 years old
Birthday:
February 10, 1989
Gender:
Location:
Waterford, Ireland
Years Programming:
6
Programming Languages:
I know a lot of: Java
I know a enough of: Visual Basic, LUA
I know a little of C, C++, C#

--MarkupLanguages--
XML, HTML

E-mail:
Private

### Friends

Page 1 of 1
1. #### farrell2k

08 Aug 2013 - 00:01
You still alive?
2. #### farrell2k

11 Jul 2013 - 18:05
yo, brotha man!
3. #### shamsham

02 Jul 2013 - 01:21
Thank you so much! :D
4. #### sasi9111

22 Jun 2013 - 01:59