Count of numbers with all digits same in a given range | Java program to count the total numbers in the range L and R which have all the digit same ; Function that count the total numbersProgram between L and R which have all the digit same ; Length of R ; tmp has all digits as 1 ; For each multiple of tmp in range 1 to 9 , check if it present in range [ L , R ] ; Increment the required count ; Driver code
import java . util . * ; class GFG { static int count_same_digit ( int L , int R ) { int tmp = 0 , ans = 0 ; int n = ( int ) Math . log10 ( R ) + 1 ; for ( int i = 0 ; i < n ; i ++ ) { tmp = tmp * 10 + 1 ; for ( int j = 1 ; j <= 9 ; j ++ ) { if ( L <= ( tmp * j ) && ( tmp * j ) <= R ) { ans ++ ; } } } return ans ; } public static void main ( String [ ] args ) { int L = 12 , R = 68 ; System . out . println ( count_same_digit ( L , R ) ) ; } }