Product of all Subarrays of an Array | Set 2 | Java program for the above approach ; Function to find the product of elements of all subarray ; Initialize the result ; Computing the product of subarray using formula ; Return the product of all elements of each subarray ; Driver code ; Given array arr [ ] ; Function Call
import java . util . * ; class GFG { static int SubArrayProdct ( int arr [ ] , int n ) { int result = 1 ; for ( int i = 0 ; i < n ; i ++ ) result *= Math . pow ( arr [ i ] , ( i + 1 ) * ( n - i ) ) ; return result ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 2 , 4 } ; int N = arr . length ; System . out . println ( SubArrayProdct ( arr , N ) ) ; } }