GFG number of digit in a number recursive

 


   public static int k = 1;

    // complete the below function

    public static int countDigits(int n)

    {

        

        if( n == 0 || n == 1 || n == 2 || n == 3 || n == 4 ||n == 5 || n == 6 || n == 7 || n == 8 || n == 9){

            return k;

        }

        k = k + 1; 

     return   countDigits(n / 10);

        

    }


Comments