hey all,
still very new, i'm trying to create an array and then get an average of the numbers. this is for a class of mine and a friend says i'm close but the book doesnt really give any further help. can you tell me where i'm going wrong?
mucho gracias
public class AvgArray
{
// Array
int[] a = {1,2,3,4,5,6};
double[] b = {6.0,4.4,1.9,2.9,3.4,3.5};
double sum;
public static int averagea(int[] array)
{
int sum = 0; //all elements together
for (int i = 0; i < a.length; i++)
{
sum += a[i];
}
return sum / a.length;
}
public static double averageb(double[] array)
{
double sum = 0; //add all of nums
for (double i = 0; i < b.length; i++)
{
sum += b[i];
}
return sum / b.length;
}
/**Main Method*/
public static void main(String args[])
{
}
}