public class Main {
    public static void main(String[] args) {

        int number = -123456;

        if(number < 0)
            number = -number;

        int count = number == 0 ? 1 : 0;
        while (number > 0) {
            number /= 10;
            count++;
        }
        System.out.println(sum);
    }
}
  • Time Complexity: O(log₁₀N) ; N is the number.
  • Space Complexity: O(1).