百度的一个笔试题(求字符串的最长数字子串的长度)

比较简单。

package a; public class CopyOfTest1 { public static void main(String ss[]) { isNum('a'); isNum('9'); System.out.println(longestNumSubString("a15bcd78efg941234k")); } static int longestNumSubString(String src) { int max = 0; int count = 0; for (int i = 0; i < src.length(); i++) { if (isNum(src.charAt(i))) { count++; if (max < count) { max = count; } } else { count = 0; } } return max; } static boolean isNum(char c) { int d = c; d = d - 48; if (d <= 9 && d >= 0) { return true; } return false; } }

【百度的一个笔试题(求字符串的最长数字子串的长度)】

    推荐阅读