Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

returning the largest and smallest numbers as an array

I’m trying to return the largest and the smallest numbers in an array as an array

for example:
int[] arr = {5, 1, 2, 4, 9, 10, 200}

public static int[] largest_smallest(int[] arr)
{
    
    
    int max = array_values.Max();
    int min = array_values.Min();
    
   //return array with largest and smallest numbers
}

How do I modify my code so it can have an output of: [200, 1]?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

like this

 int [] result  = { min, max};

 return result;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading