Product of N terms of a given Geometric series | Java program for the above approach ; Function to calculate product of N terms of geometric series ; Find the product of first and the last term ; Return the sqrt of the above expression to find the product ; Driver Code ; Given first term and common ratio ; Number of terms ; Function Call
import java . util . * ; class GFG { static float productOfGP ( float a , float r , int n ) { int an = ( int ) ( a * ( int ) ( Math . pow ( r , n - 1 ) ) ) ; return ( int ) Math . sqrt ( ( int ) Math . pow ( a * an , n ) ) ; } public static void main ( String args [ ] ) { float a = 1 , r = 2 ; int N = 4 ; System . out . print ( productOfGP ( a , r , N ) ) ; } }