Product of all the pairs from the given array | Java implementation to find the product of all the pairs from the given array ; Function to return the product of the elements of all possible pairs from the array ; To store the required product ; Nested loop to calculate all possible pairs ; Multiply the product of the elements of the current pair ; Return the final result ; Driver code
import java . util . * ; class GFG { static final int mod = 1000000007 ; static int productPairs ( int arr [ ] , int n ) { int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { product *= ( arr [ i ] % mod * arr [ j ] % mod ) % mod ; product = product % mod ; } } return product % mod ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int n = arr . length ; System . out . print ( productPairs ( arr , n ) ) ; } }