Skip to content

Instantly share code, notes, and snippets.

@thearyanag
Created September 9, 2022 14:08
Show Gist options
  • Select an option

  • Save thearyanag/9c12533e53f8dbc992621b846f773ab9 to your computer and use it in GitHub Desktop.

Select an option

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?
// 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