方法一:
static int stringSize1(int x){ int count = 0; while (x > 0) { count++; x /= 10; } return count; }
方法二:
1 finalstaticint[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, 2 99999999, 999999999, Integer.MAX_VALUE }; 3 4 // Requires positive x 5 staticintstringSize(intx) { 6 for(inti=0; ; i++) 7 if(x <= sizeTable[i]) 8 returni+1; 9 }