[JAVA]快速判断一个int值是几位数-转

final static int[] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
  99999999, 999999999, Integer.MAX_VALUE };
static int sizeOfInt(int x) {
  for (int i = 0;; i++)
    if (x <= sizeTable[i])
      return i + 1;
}

posted @ 2017-07-20 09:31  firerdong  阅读(2751)  评论(0编辑  收藏  举报