Count of squares that can be drawn without lifting the pencil | Java implementation of the approach ; Function to return the count of squares that can be formed ; Driver code
class GFG { static int countSquares ( int n ) { return ( int ) ( Math . pow ( n , 2 ) - ( 2 * n ) + 2 ) ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( countSquares ( n ) ) ; } }