Skip to content

Instantly share code, notes, and snippets.

@zhjwpku
Created September 14, 2017 13:28
Show Gist options
  • Save zhjwpku/7c1a8496a2515ee2c3c52bb619a8a5a3 to your computer and use it in GitHub Desktop.
Save zhjwpku/7c1a8496a2515ee2c3c52bb619a8a5a3 to your computer and use it in GitHub Desktop.
public class MaxNumString {
public int Continumax(String intputStr, StringBuffer outputStr){
int maxlength=0;
StringBuffer maxNumberStr = null;
int nowlength=0;
StringBuffer nowNumberStr = null;
for(int i=0;i<intputStr.length();i++){
if((intputStr.charAt(i))>=48 && (intputStr.charAt(i))<=57){
if(nowlength==0){
nowNumberStr = new StringBuffer(String.valueOf(intputStr.charAt(i)));
nowlength++;
}else{
nowNumberStr.append(intputStr.charAt(i));
nowlength++;}
if(nowlength>=maxlength){
maxNumberStr = nowNumberStr;
maxlength = nowlength;
}
}else{
nowlength=0;
nowNumberStr =null;
}
}
System.out.println(maxNumberStr);
return maxlength;
}
public static void main(String[]args) {
MaxNumString test = new MaxNumString();
System.out.println(test.Continumax("abcd12345ss54321", null));
System.out.println(test.Continumax("abcd12345ed125ss123456789", null));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment