Count squares with odd side length in Chessboard | Java implementation of the approach ; Function to return the count of odd length squares possible ; To store the required count ; For all odd values of i ; Add the count of possible squares of length i ; Return the required count ; Driver code
class GFG { static int count_square ( int n ) { int count = 0 ; for ( int i = 1 ; i <= n ; i = i + 2 ) { int k = n - i + 1 ; count += ( k * k ) ; } return count ; } public static void main ( String [ ] args ) { int N = 8 ; System . out . println ( count_square ( N ) ) ; } }