Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AverageFunction
- {
- public static double average(double... values) // return method returns value void method does not return result.
- {
- double sum = 0;
- for (double v : values) {
- sum += v;
- }
- return values.length == 0 ? 0 : sum / values.length;
- }
- public static void main(String[] args)
- {
- double[] score = {1,3,4,5};
- System.out.println(average(score));
- System.out.println(average(1, 3, 4, 5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement