Count of pairs satisfying the given condition | Java implementation of the approach ; Function to return the number of pairs satisfying the equation ; Converting integer b to String by using to_String function ; Loop to check if all the digits of b are 9 or not ; If '9' doesn 't appear  then break the loop ; If all the digits of b contain 9 then multiply a with String length else multiply a with String length - 1 ; Return the number of pairs ; Driver code
class GFG { static int countPair ( int a , int b ) { String s = String . valueOf ( b ) ; int i ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) != '9' ) break ; } int result ; if ( i == s . length ( ) ) result = a * s . length ( ) ; else result = a * ( s . length ( ) - 1 ) ; return result ; } public static void main ( String [ ] args ) { int a = 5 , b = 101 ; System . out . print ( countPair ( a , b ) ) ; } }