```
package deviation;
import java.util.Scanner;
public class Deviation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter n: ");
int n = input.nextInt();
System.out.println("Enter " + n + " numbers: ");
double[] x = new double[n];
int i;
for (i = 0; i<n; i++) {
x[i] = input.nextDouble();
}
double mean = mean(x, i);
double deviation = deviation(x, i);
System.out.println("The mean is " + mean);
System.out.println("The standard deviation is " + deviation);
}
public static double deviation(double[] x, double i) {
double mean = mean(x, i);
double num = 0;
num += Math.pow(x[i] - mean, 2);
double n;
double den = n - 1;
double deviation = Math.sqrt((num/den));
return deviation;
}
public static double mean(double[] x, double i) {
double sum = 0;
for(int j=0;j<i;j++) {
sum += x[j];
}
return sum / i;
}
}
```

## Recommended Answers

Jump to PostNo time now to read the code, but...

the message is clear - you have used double where an int is required. The compiler won't allow an automatic conversion because doubles can have fractional values but ints can't.

Jump to PostI presume it's referring to your mean method - the second parameter isn't a data value, it's some kind of aray index or size, which therefore has to be an integer type.

## All 7 Replies

sejalp26
0
Newbie Poster

sejalp26
0
Newbie Poster

sejalp26
0
Newbie Poster

JamesCherrill
4,349
Most Valuable Poster
Moderator
Featured Poster

sejalp26
0
Newbie Poster

JamesCherrill
4,349
Most Valuable Poster
Moderator
Featured Poster

sejalp26
0
Newbie Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.