Prefix Product Array | Java program to generate Prefix Product Array ; Function to generate prefix product array ; Update the array with the product of prefixes ; Print the array ; Driver Code
class GFG { static int prefixProduct ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i ] * a [ i - 1 ] ; } for ( int j = 0 ; j < n ; j ++ ) { System . out . print ( a [ j ] + " , ▁ " ) ; } return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 2 , 4 , 6 , 5 , 10 } ; int N = 5 ; prefixProduct ( arr , N ) ; } }