题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
// mark一下啦 // 正则表达式提取出数字 split(regex) "\\D" 非数字 import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String s = in.nextLine(); // 正则表达式 非数字 String regex = "\\D"; String[] strings = s.split(regex); String ans = ""; int ansLength = 0; for (String eachStr : strings) { int eachLength = eachStr.length(); ansLength = Math.max(ansLength, eachLength); } for (String eachStr : strings) { int eachLength = eachStr.length(); if (eachLength == ansLength) { ans += eachStr; } } System.out.println(ans + "," + ansLength); } } }