lindsey
Dec 7th, 2002, 11:10 AM
:( hi i am learning java, so forgive me. i am trying to do a sum requiring 2 arrays. the sum involves the average, of arrays. i need also to use a method for calculating the array by the power of 2 for each array ect. But i will try and work them out myself if any one can confirm or put me on the right track. As i don't know how to call these methods in my answer.
here is my code, if i declared it wrong please advise
import java.io.*;
public class LinearLeast
{ // start of new class
public static void main(String[]args)
{ //start of main method
//values for array x
double [] arrX ={-4.91,-3.84,-2.41,-2.62,-3.78,-0.52,-1.83,-2.01,0.28,1.08,
-0.94,0.59,0.69,3.04,1.01,3.60,4.53,5.13,4.43,4.12};
// values for array y
double [] arrY ={-8.18,-7.49,-7.11,-6.15,-5.62,-3.30,-2.05,-2.83,-1.16,0.52,
0.21,1.73,3.96,4.26,5.75,6.67,7.70,7.31,9.05,10.05};
//defines the avarage method
public double average (double arr[])
{
double sumA =0;
double AverageB =0;
if (arr.lenght >=1)
{
for(int i=0; i< arr.lenght; i++)
{
sumA +=arr[i];
}
AverageB = sumA / arr.lenght;
}
}
System.out.println("array x "+arrX+"\n array y"+arrY);
System.out.println(" average of array X "+AverageB);
System.out.println(" average of array Y "+AverageB);
} //end of main method
} // end of class
thanks if you can help
here is my code, if i declared it wrong please advise
import java.io.*;
public class LinearLeast
{ // start of new class
public static void main(String[]args)
{ //start of main method
//values for array x
double [] arrX ={-4.91,-3.84,-2.41,-2.62,-3.78,-0.52,-1.83,-2.01,0.28,1.08,
-0.94,0.59,0.69,3.04,1.01,3.60,4.53,5.13,4.43,4.12};
// values for array y
double [] arrY ={-8.18,-7.49,-7.11,-6.15,-5.62,-3.30,-2.05,-2.83,-1.16,0.52,
0.21,1.73,3.96,4.26,5.75,6.67,7.70,7.31,9.05,10.05};
//defines the avarage method
public double average (double arr[])
{
double sumA =0;
double AverageB =0;
if (arr.lenght >=1)
{
for(int i=0; i< arr.lenght; i++)
{
sumA +=arr[i];
}
AverageB = sumA / arr.lenght;
}
}
System.out.println("array x "+arrX+"\n array y"+arrY);
System.out.println(" average of array X "+AverageB);
System.out.println(" average of array Y "+AverageB);
} //end of main method
} // end of class
thanks if you can help