In all the other cases I could find, it was due to code not in a method or incorrect bracketing, however I have checked all these. My code is this;
import java.util.*;
public class averages {
public static void main(String[] args)
{
//initializing
double mean = 0;
double deviation = 0;
int i = 0;
double dataset = new double[10];
double sum = 0;
double subdev = 0;
double subsum = 0;
double dev = 0;
//getting the numbers
for (i = 0; i <= 9 ; i++)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a number");
dataset[i] = input.nextDouble();
}
//calling the function to get
avgarray(dataset[]);
System.out.println("Average is " + mean);
devequasion(dataset[]);
System.out.println("Deviation is " + subdev);
}
public static double avgarray(double[] arraydata)
{
sum = 0;
for (i = 0; i <= 9 ; i++)
{
sum += arraydata[i];
}
mean = sum / 10;
return mean;
}
public static double devequasion(double[] devdata)
{
subsum = 0;
for (i = 0; i <= 9 ; i++)
{
subsum += devdata[i]*devdata[i];
}
dev = math.sqrt((sum - avgarray(devdata[]))/ 9.0);
return dev;
}
}
Everything looks correct, but the errors will not go away.
You have quite a few problems there, such as:
dataset[]rather thandataset.avgarrayanddevequasionthat are used but not declared (mean,sum,subsum,i,dev). The fact that these are declared inmainis not relevant.main, other thatiof course).java.util.Scannerfor the data input.Mathwith a capitalM.If you use an IDE like Eclipse, you will find it a lot easier to see and fix these problems. For beginners, that’s a
${DEITY}-send.By all means pump your code into
javacas a final step if you have to (headless builds, compatibility and so forth) but do your initial development with an IDE, you’ll find it much faster.Here’s a version with all those syntactical problems rectified, and a few other minor tweaks, such as the removal of unnecessary variables:
Don’t use this verbatim if it’s homework, you would be foolish to assume your educators were not actively searching the web for plagiarism.