Advertisement
svetlyo0659

Untitled

Feb 26th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. public class AverageFunction
  2. {
  3.   public static double average(double... values) // return method returns value void method does not return result.
  4.   {
  5.     double sum = 0;
  6.     for (double v : values) {
  7.       sum += v;
  8.     }
  9.     return values.length == 0 ? 0 : sum / values.length;
  10.  
  11.   }
  12.  
  13.   public static void main(String[] args)
  14.   {
  15.     double[] score = {1,3,4,5};
  16.     System.out.println(average(score));
  17.     System.out.println(average(1, 3, 4, 5));
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement