题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
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 text = sc.next(); String[] arr = text.split("[a-zA-Z]"); int ans = 0; StringBuilder res = new StringBuilder(); for (String s : arr) { if (s.length() > ans) { ans = s.length(); res = new StringBuilder(s); } else if (s.length() == ans) { res.append(s); } } System.out.printf("%s,%d\n", res, ans); } } }