Average Salary Excluding the Minimum and Maximum Salary in Java

 Average Salary Excluding the Minimum and Maximum Salary in Java.

    public double average(int[] salary) { 

        int i; 

        int big = salary[0]; 

        int small = salary[0]; 

        double sum = salary[0]; 

        for (i = 1; i < salary.length; i++) { 

            sum += salary[i]; 

            big = (big > salary[i]) ? big : salary[i]; 

            small = (small < salary[i]) ? small : salary[i]; 

         } 

        return ((sum-big-small)/(i-2)); 

    }

Comments

Popular posts from this blog

Automate Blog Post creation using Blogger APIs and Python

The beginning of Data Quest

How to Clone a MongoDB Database Between Docker Containers

Understanding Swagger and OpenAPI Specifications

How to root, flash twrp, unlock bootloader and install custom ROM via Linux