Write Method Returns Difference Largest Smallest Item Integer Array Static Int Maxdiff Int Q37077591

Write a method that returns the difference between the largestand smallest item in an integer array static int maxDiff(int []arr) Write a main method to test the above method.


Solution


import java.util.Arrays;//Main.javapublic class Main { static int maxDiff(int [] arr){ int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for(int i = 0;i<arr.length;i++){ if(max < arr[i]){ max = arr[i]; } if(min > arr[i]){

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.