Hiya, im new to this site but it seems like a very useful comunity :)
Im new to java programming as well and i have to write a class file to deal with calculating the maximum, minimum, average(mean), population variance and sample variance from an array which is entered by the user which is delt with in the array application .
This is what i have done so far but when i go to compile it i get an error saying "illegal start of type" at this line (for double i = o; i < doubleArray.length; i++); and i really cant see why its an illegal start :(
im sure there are many other errors too :(
// ArrayCalculator Class file
// Author: 590028847
// 08/11/09
public class ArrayCalculator
{
// A method for returning the maximum number in the array
public double max;
(for double i = o; i < doubleArray.length; i++);
{
while(array[i]>max)
{
max = array[i];
}
}
return ("Maximum value:" + max);
// A method for returning the minimum number in the array
public double min;
for(double i = o; i < doubleArray.length; i++)
{
while(array[i]<min)
{
min = array[i];
}
}
return ("Minimum value:" + min);
// A method to calculate the sum of the array
public double sum = 0;
for (double i = 0; i < doubleArray.length; i++){}
// A method to return the mean of the array
public double mean = sum / doubleArray.length;
return ("Average (mean):" = mean);
// A method to return the population variance
double populationVariance = Math.pow((sum - mean),2) / doubleArray.length;
return ("Population Variance:" = populationVariance);
// A method to return the sample variance
double sampleVariance = Math.pow((sum - mean),2) / ( doubleArray.length - 1);
return ("Sample Variance:" = sampleVariance);
}
Then the application gets an error of illegal start of opperation at line 22
// ArrayCalculatorApp Application
// Program does not carry out any exception handling or type checking on input
// Generates an array of type double whose contents are specified by the user
// Author: 590028847
// 08/11/09
// Import classes used from java .io package
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ArrayCalculatorApp
{
public static void main(String[] args) throws java.io.IOException{
// Create BufferedReaderClass instance
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader keyboardInput = new BufferedReader(input);
// Declair and assign values to array
System.out.println("Please enter values seperated by a comma then a space, e.g 1, 2, 3");
public double[]doubleArray = {(keyboardInput.readLine()).doubleValue()};
// To print details to screen
System.out.println(max)
System.out.println(min)
System.out.println(mean)
System.out.println(populationVariance)
System.out.println(sampleVariance)
}
}
help would be much apreciated to a newbie at programming and this site
Cheers
Matt