import java.util.Arrays; public class HighLow{ public static int[] printLargestAndSmallest(int[] nums){ return nums == null || nums.length==0 ? null : new int[]{Arrays.stream(nums).min() .getAsInt(),Arrays.stream(nums).max().getAsInt()}; } }
- import java.util.Arrays;
- public class HighLow{
- public static int[] printLargestAndSmallest(int[] nums){
int low[] = nums;int high[] = nums;int lowest = nums[0];int highest = nums[0];int count = 0;for(int i = 0; i < nums.length;i+=2){int num1 = nums[i];int num2 = nums[i+1];if(num1<num2){low[count] = num1;high[count] = num2;count++;}else{low[count] = num2;high[count] = num1;count++;}lowest = low[0];highest = high[0];for(int j = 1; j < low.length; j++){if(low[j] < lowest){lowest = low[j];}}for(int j = 1; j < high.length; j++){if(high[j] > highest){highest = high[j];}}}int[] finalHighLow = new int[2];finalHighLow[0] = lowest;finalHighLow[1] = highest;return finalHighLow;- return nums == null || nums.length==0 ? null : new int[]{Arrays.stream(nums).min()
- .getAsInt(),Arrays.stream(nums).max().getAsInt()};
- }
- }