Sum of an Infinite Geometric Progression ( GP ) | Java program for the above approach ; Function to calculate the sum of an infinite Geometric Progression ; Case for Infinite Sum ; Store the sum of GP Series ; Print the value of sum ; Driver Code
import java . util . * ; class GFG { static void findSumOfGP ( double a , double r ) { if ( Math . abs ( r ) >= 1 ) { System . out . print ( " Infinite " ) ; return ; } double sum = a / ( 1 - r ) ; System . out . print ( sum ) ; } public static void main ( String [ ] args ) { double A = 1 , R = 0.5 ; findSumOfGP ( A , R ) ; } }