Created
September 9, 2022 14:08
-
-
Save thearyanag/9c12533e53f8dbc992621b846f773ab9 to your computer and use it in GitHub Desktop.
Find the average of largest and smallest numbers in an unsorted integer array?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Find the average of largest and smallest numbers in an unsorted integer array? | |
| // Eg. [1, 4, 3, 2] => average = (1+4)/2 = 2.5[1, 4, 3, 4] => average = (1+4+4)/3 = 3 | |
| import java.util.*; | |
| double avg(int arr[]) | |
| { | |
| Arrays.sort(arr); | |
| return (arr[0]+arr[arr.length-1])/2; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment