Sum of first n terms of a given series 3 , 6 , 11 , ... . . | Java program to find sum of first n terms ; Function to calculate the sum ; starting number ; Common Ratio ; Common difference ; Driver code ; N th term to be find ; find the Sn
import java . io . * ; class GFG { static int calculateSum ( int n ) { int a1 = 1 , a2 = 2 ; int r = 2 ; int d = 1 ; return ( n ) * ( 2 * a1 + ( n - 1 ) * d ) / 2 + a2 * ( int ) ( Math . pow ( r , n ) - 1 ) / ( r - 1 ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . print ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }