Sum of all the numbers in the Nth row of the given triangle | Java implementation of the approach ; Function to return the sum of the nth row elements of the given triangle ; Driver code
class GFG { static int getSum ( int n ) { return ( ( n - 1 ) + ( int ) Math . pow ( n , 2 ) ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( getSum ( n ) ) ; } }