fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Employee {
  8. final int salary;
  9.  
  10. public Employee(int salary) {
  11. this.salary = salary;
  12. }
  13. }
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Ideone
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. Employee[] employees = new Employee[] { new Employee(22), new Employee(13), new Employee(5) };
  21. double avg = calcAverage(employees);
  22. System.out.println(avg);
  23. }
  24.  
  25. private static double calcAverage(Employee[] employees) {
  26. double sum = Arrays.stream(employees).map(e -> e.salary).reduce(0, (a, b) -> a + b);
  27. return sum / employees.length;
  28. }
  29. }
Success #stdin #stdout 0.09s 49032KB
stdin
Standard input is empty
stdout
13.333333333333334