Sum of all ordered pair | Java program to implement the above approach ; Function to calculate the sum of all pair - products ; Stores sum of array ; Update sum of the array ; Driver code
import java . util . * ; class GFG { static int sumOfProd ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } return sum * sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 5 , 4 } ; int N = arr . length ; System . out . print ( sumOfProd ( arr , N ) ) ; } }