- public class Test {
- final static int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
- 99999999, 999999999, Integer.MAX_VALUE };
- public static void main(String[] args) {
- System.out.println(sizeOfInt(1234));
- }
static int sizeOfInt(int x) {
for (int i = 0;; i++)
if (x <= sizeTable[i])
return i + 1;
}
- }
时间: 2024-10-26 16:28:00