text: Sum of the first N terms of the series 2 , 10 , 30 , 68 , ... . | Java program to find sum of first n terms ; Function to calculate the sum ; Driver code ; number of terms to be included in the sum ; find the Sum
code: public class GFG { static int calculateSum ( int n ) { return n * ( n + 1 ) / 2 + ( int ) Math . pow ( ( n * ( n + 1 ) / 2 ) , 2 ) ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . println ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }