Program to find Sum of the series 1 * 3 + 3 * 5 + ... . | Java program to find sum of first n terms ; Sn = n * ( 4 * n * n + 6 * n - 1 ) / 3 ; Driver Code ; number of terms to be included in the sum ; find the Sn
class GFG { static int calculateSum ( int n ) { return ( n * ( 4 * n * n + 6 * n - 1 ) / 3 ) ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }