Count of numbers in range [ L , R ] with LSB as 0 in their Binary representation | Java implementation of the approach ; Function to return the count of required numbers ; If rightmost bit is 0 ; Return the required count ; Driver code ; Call function countNumbers
import java . io . * ; class GFG { static int countNumbers ( int l , int r ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( ( i & 1 ) == 0 ) count += 1 ; } return count ; } public static void main ( String [ ] args ) { int l = 10 , r = 20 ; System . out . println ( countNumbers ( l , r ) ) ; } }