I am not finished working on this program, so I know there may be other mistakes. I am currently getting the '.class' expected error, and for some reason I can't see that mistake.
I am using jGrasp and this is a project for my Intro to Java class.
import java.util.*;
import static java.lang.Math.*;
public class Final_Project_Test_Process_With_Arrays
//Final Project
//Mean and Standard Deviation
//13.04.27
{
public static void main(String[] args) {
//Allow for the user to input numbers
Scanner kb = new Scanner(System.in);
System.out.println("How many numbers?");
int amount = kb.nextInt();
double[] nums = new double[amount];
for (int count = 0; count < nums.length; count++) {
System.out.print("Enter number " + (count + 1) + ": ");
nums[count] = kb.nextDouble();
}
System.out.print("The mean of ");
for (int index = 0; index < nums.length; index++) {
System.out.print(nums[index] + ", ");
}
System.out.printf("is " + "%.2f", calcMean(nums));
System.out.println();
System.out.print("The Standard Deviation of ");
for (int counter = 0; counter < nums.length; counter++) {
System.out.print(nums[counter] + ", ");
}
System.out.print("is " + calcStandardDeviation(amount, mean,double...nums));
System.out.println();
}
public static double calcMean(double[] nums) {
double sum = 0;
double mean = 0;
for (int index = 0; index < nums.length; index++) {
sum = sum + nums[index];
}
if (nums.length != 0)
mean = sum / nums.length;
return mean;
}
public static double calcStandardDeviation(int amount, double mean, double... nums) {
double squared = 0;
double sum = 0;
double radicand = 0;
for (double num : nums) {
squared = pow((num - mean), 2);
sum = sum + squared;
}
radicand = sum / amount;
double standardDeviation = sqrt(radicand);
return standardDeviation;
}
}
I know there is a simple answer, and I have done searches to help, but being a beginner at this, it's taking me too long to apply answers to other similar posts to my own problem.
Error messages are as follows:
Final_Project_Test_Process_With_Arrays.java:38: error: '.class' expected
System.out.print("is " + calcStandardDeviation(amount, mean, double ... nums));
^
Final_Project_Test_Process_With_Arrays.java:38: error: ')' expected
System.out.print("is " + calcStandardDeviation(amount, mean, double ... nums));
^
Final_Project_Test_Process_With_Arrays.java:38: error: ';' expected
System.out.print("is " + calcStandardDeviation(amount, mean, double ... nums));
^
Final_Project_Test_Process_With_Arrays.java:38: error: illegal start of expression
System.out.print("is " + calcStandardDeviation(amount, mean, double ... nums));
^ 4 errors
The ^ is always pointing to amount.
A problem that I can see is the way you are invoking the calcStandardDeviation
method -
System.out.print("is " + calcStandardDeviation(amount, mean, double ... nums));
That actually should be -
System.out.print("is " + calcStandardDeviation(amount, mean, nums));
Also, you haven't declared the variable mean
(that you are passing to the method).