Sum and Product of minimum and maximum element of an Array | Java program for the above approach ; Function to get sum ; Function to get product ; Driver code ; sorting the array ; min element would be the element at 0 th index of array after sorting ; max element would be the element at ( n - 1 ) th index of array after sorting
import java . io . * ; import java . util . Arrays ; class GFG { static int findSum ( int minEle , int maxEle ) { return minEle + maxEle ; } static int findProduct ( int minEle , int maxEle ) { return minEle * maxEle ; } public static void main ( String [ ] args ) { int [ ] arr = { 12 , 1234 , 45 , 67 , 1 } ; int n = arr . length ; Arrays . sort ( arr ) ; int minEle = arr [ 0 ] ; int maxEle = arr [ n - 1 ] ; System . out . println ( " Sum ▁ = ▁ " + findSum ( minEle , maxEle ) ) ; System . out . println ( " Product ▁ = ▁ " + findProduct ( minEle , maxEle ) ) ; } }