H3C面试编程题
package h3c;
//get the maxIntString from any given string
public class MaxIntString {
public static void main(String[] args) {
String string = "a11q2334ffsd4234234a";
String string2 = getMaxIntString(string);
System.out.println(string2);
}
static String getMaxIntString(String string){
//store the intString
StringBuilder stringBuilder = null;
//the index of intString
int count = 0 ;
//the length of intString
int intLength = 0;
//the length of string
int len = string.length();
for(int i=0; i<len;){
//the char range (0,9)
if (string.charAt(i)>48
&&
string.charAt(i)<57) {
count++;
if(intLength < count){
intLength = count;
stringBuilder = new StringBuilder();
for(int j=i-count+1; j<=i;j++){
stringBuilder.append(string.charAt(j));
}
}
i++;
}else {
count = 0;
i++;
}
}
return stringBuilder.toString();
}
}