Find the number of squares inside the given square grid | Java implementation of the approach ; Function to return the number of squares inside an n * n grid ; Driver code
class GFG { static int cntSquares ( int n ) { return n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ; } public static void main ( String args [ ] ) { System . out . println ( cntSquares ( 4 ) ) ; } }