- import java.util.*;
- import javafx.util.*;
-
- public class M
- {
- public static Pair<Integer, Integer> getMinMax(int [] array)
- {
- int min, max;
- int index;
-
- if(array.length%2 == 0)
- {
- if(array[0] < array[1])
- {
- min = array[0];
- max = array[1];
- }
- else
- {
- min = array[1];
- max = array[0];
- }
- index = 2;
-
- }
- else
- {
- min = max = array[0];
- index = 1;
- }
-
- for(int i = index; i < array.length-1; i++)
- {
- if(array[i] < array[i+1])
- {
- if(min > array[i])
- min = array[i];
- if(array[i+1] > max)
- max = array[i+1];
- }
- else
- {
- if(min > array[i+1])
- min = array[i+1];
- if(max < array[i])
- max = array[i];
- }
- }
-
- return (new Pair<Integer, Integer>(min, max));
- }
-
- public static int [] getArray(int n)
- {
- int [] array = new int[n];
- Random r = new Random();
-
- for(int i = 0; i < n; i++)
- array[i] = r.nextInt(100);
-
- return array;
- }
-
- public static void main(String args[])
- {
- int [] array = getArray(100);
-
- Pair<Integer, Integer> p = getMinMax(array);
-
- System.out.println("Min: "+p.getKey()+" Max: "+p.getValue());
- }
- }
-