题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String[] s = sc.nextLine().split("[^0-9]"); int res = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length; i++) { if (s[i].length() > res) { res = s[i].length(); } } for (int i = 0; i < s.length; i++) { if (s[i].length() == res) { sb.append(s[i]); } } System.out.println(sb.toString() + "," + res); } } }#利用正则表达来分隔字符串#