private static int NumberLength(int x) { int n = 0; while (x > 0) { n++; x /= 10; } return n == 0 ? 1 : n; } }