Count of all possible numbers not exceeding M having suffix N | Java program to implement the above approach ; Function to count the no . of digits of N ; Function to count all possible numbers having Suffix as N ; Difference of the A . P ; Count of the number of terms ; Driver code
import java . util . * ; class GFG { static int digitsOf ( int num ) { return Integer . toString ( num ) . length ( ) ; } static int count ( int a , int tn ) { int diff = ( int ) Math . pow ( 10 , digitsOf ( a ) ) ; return ( ( tn - a ) / diff ) + 1 ; } public static void main ( String [ ] args ) { int n = 25 , m = 4500 ; System . out . println ( count ( n , m ) ) ; } }