题目描述:读入一个字符串,输出字符串str中的连续最长的数字串
示例描述:
输入:bhjt6767jhh334608
输出:334608
代码实现:
public class MostLong {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
String result = "";
int count = 0;
char[] arr = str.toCharArray();
for (int i = 0; i < arr.length; i++) {
if ('0' <= arr[i] && '9' >= arr[i]) {
count = 1;
int index = i;
for (int j = i + 1; j < arr.length; j++) {
if ('0' <= arr[j] && '9' >= arr[j]) {
count++;
index = j;
} else {
break;
}
}
if (count > result.length()) {
result = str.substring(i, index + 1);
} else {
continue;
}
}
}
System.out.println(result);
}
}