Count triangles required to form a House of Cards of height N | Java implementation of the above approach ; Function to find number of triangles ; Driver Code ; Function call
import java . lang . * ; class GFG { public static int noOfTriangles ( int n ) { return ( n * ( n + 2 ) * ( 2 * n + 1 ) / 8 ) ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . print ( noOfTriangles ( n ) ) ; } }