Answer to Question #4893 in Java | JSP | JSF for John Morales

Question #4893
Create a method called avgValue, which takes an array of doubles as an input parameter and returns the average value of the entries in the array.

Example:

data1:{1.1,2.5,3.0}
==> 2.2
1
Expert's answer
2011-10-27T10:35:53-0400
public class AvrValue {
public static double avrValue(double[] arr)
{
double sum = 0;
for (double d : arr)
sum += d;
return sum /
arr.length;
}

public static void main(String[] args)
{
System.out.println(avrValue(new double[] { 1.1, 2.5, 3.0
}));
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS