题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String s = in.nextLine(); f(s); } } private static void f(String s){ String[] a = s.split("[^0-9]+"); int[] l = new int[a.length]; for (int i = 0; i < a.length; i++){ l[i] = a[i].length(); } int max = 0; for (int i = 0; i < a.length; i++){ if (l[i] > max){ max = l[i]; }; } for (int i = 0; i < a.length; i++){ if (a[i].length() == max){ System.out.print(a[i]); } } System.out.print("," + max); System.out.println(); } }