Find n | Java Program to calculate nth term of a series ; func for calualtion ; for summation of square of first n - natural nos . ; summation of first n natural nos . ; return result ; Driver Code
import java . io . * ; class GFG { static int seriesFunc ( int n ) { int sumSquare = ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; int sumNatural = ( n * ( n + 1 ) / 2 ) ; return ( sumSquare + sumNatural + 1 ) ; } public static void main ( String args [ ] ) { int n = 8 ; System . out . println ( seriesFunc ( n ) ) ; n = 13 ; System . out . println ( seriesFunc ( 13 ) ) ; } }