Count squares of size K inscribed in a square of size N | Java implementation of the above approach ; Function to calculate the number of squares of size K in a square of size N ; Stores the number of squares ; Driver Code ; Size of the bigger square ; Size of smaller square
import java . util . * ; class GFG { static int No_of_squares ( int N , int K ) { int no_of_squares = 0 ; no_of_squares = ( N - K + 1 ) * ( N - K + 1 ) ; return no_of_squares ; } public static void main ( String [ ] args ) { int N = 5 ; int K = 3 ; System . out . print ( No_of_squares ( N , K ) ) ; } }