In the problem ”Average Salary Excluding the Minimum and Maximum Salary” we are given a salary array. where each element in the array represents the salary of different employees. Each value in the array is unique.
Our task is to calculate the average salary of the employee excluding the minimum and the maximum salary.
Explanation:
In the let the salary array 9000 is the maximum salary and 1000 is the minimum salary. As we need to find the average salary excluding the minimum and maximum salary so we will not add these values to the total sum. The total sum is 19000 so the average is 19000/4 that is 4750.
let salary |
9000 | 8000 | 2000 | 3000 | 6000 |1000 |
maximum salary minimum salary |
sum of all salary=29000 |
total salary Excluding the Minimum and Maximum salary=29000-9000-1000=19000 |
Average Salary Excluding the Minimum and Maximum Salary=19000/4=4750 |
Approach
This is a basic math problem. Our task is to find the minimum and the maximum salary then find the average of the remaining salary. We will follow these steps:
- Initialize minimum salary with INT_MAX, the maximum salary with INT_MIN. We will use a variable to store the salary sum so initialize it with 0.
- Traverse the array and add each salary to the sum. Meanwhile, also update the value of the minimum salary and maximum salary.
- If the value of n is smaller than three then the average salary will be zero else average salary will be (total salary-the minimum salary-the maximum salary)/(n-2).
- We will multiply (n-2) with 1.0 because the average salary can be a double value.
Step by stepSolved in 2 steps
- Write and test a Java method minimum() that returns the minimum of an array of n integers.arrow_forwardWrite a program in c that create a 5-by-6 array. All elements in the array are random integer numbers between 1 and 100. Then, calculate the mean values of each column, and also find the minimums and maximums of each column. Print out the array, mean values, minimums,arrow_forwardWrite a java program that takes 20 integer inputs from user and stores them in an array. Then print the following: • number of positive numbers in array • number of negative numbers in array • number of odd numbers in array • number of even numbers in array • number of Os in array.arrow_forward
- An array is declared as short Lot[67]. The address of Lot is 0x2877. What is the address of Lot[40]? Give your answer in 4 hexadecimal digits (include leading zeros). An array is declared as int State[29]. The address of State is 0xF988. What is the address of State[21]? Give your answer in 4 hexadecimal digits (include leading zeros). An array is declared as short Night[29]. The address of Night is 0xBE47. What is the address of Night[26]? Give your answer in 4 hexadecimal digits (include leading zeros).arrow_forwardUse Java to write a program that prompts the user for a positive odd integer , generates a normal magic square of order size of that integer, and prints it with numbers right-justified and aligned in evenly-spaced columns. (Magic square definition: https://en.wikipedia.org/wiki/Magic_square. Can assume that the numbers in the square are 3 digits or less (i.e. size ≤ 31). Have the construction of the 2D integer array magic square take place in a public static method getMagicSquare that takes in an integer n as a parameter and returns the 2D integer array magic square as specified. Your main method should perform input and output (I/O) and call this method to perform the computation. Methods for generating a magic square : Assign 1 to our initial current position: the bottom row, middle column. Place each successive value (up to size * size) in the first of the following positions that is unoccupied: (1) one space down and to the right, or (2) one space up. Positions wrap around…arrow_forwardConsider an array of length n containing unique integers in random order and in the range 1 to n + 1. For example, an array of length 5 would contain 5 unique integers selected randomly from the integers 1 through 6. Thus, the array might contain 3 6 5 1 4. Of the integers 1 through 6, notice that the 2 was not chosen and is not in the array. Write Java code that finds the integer that does not appear in such an array. Your solution should use a. O(n²) operationsarrow_forward
- i need to make sure for the answer javaarrow_forwardUsing JAVA, write a method that swaps two rows of a two-dimensional array. The row indices to be swapped are passed as parameters to the method (Assume row indices are valid indices). Write a test program to demonstrate correct operation of the method.arrow_forwardThe programming language used is Javaarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY