方法一 private static int getNumLenght(long num){ num = num>0?num:-num; return String.valueOf(num).length(); } 方法二 private static int getNumLenght(long num){ num = num>0?num:-num; if (num==0) { return 1; } return (int) Math.log10(num)+1; } 方法三 private static int getNumLenght(long num){ if (num==0) { return 1; } int lenght = 0; for (long temp = num ; temp != 0; temp/=10){ lenght++; } return lenght; }