Number of perfect squares between two given numbers | An efficient solution to count square between a and b ; Driver Code
class CountSquares { double countSquares ( int a , int b ) { return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ; } } public class PerfectSquares { public static void main ( String [ ] args ) { int a = 9 , b = 25 ; CountSquares obj = new CountSquares ( ) ; System . out . print ( " Count ▁ of ▁ squares ▁ is ▁ " + ( int ) obj . countSquares ( a , b ) ) ; } }