牛客网:读入一个字符串str,输出字符串str中的连续最长的数字串

https://www.nowcoder.com/practice/bd891093881d4ddf9e56e7cc8416562d?tpId=182&&tqId=34785&rp=1&ru=/activity/oj&qru=/ta/exam-all/question-ranking

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/*
 * 字符串中找出连续最长的数字串
 */
 
public class Main {
public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    StringBuilder sb = new StringBuilder();
    for(int i=0;i='0' && str.charAt(i)<='9'){
            sb.append(str.charAt(i));
        }else{
            sb.append(" ");
        }
    }
    String s = sb.toString();
    String [] ss = s.split(" ");
    int a = ss[0].length();
    int b = 0;
    for(int i=1;ia){
            a = ss[i].length();
            b= i;
        }else{
            continue;
        }
    }
    System.out.println(ss[b]);
}
}

你可能感兴趣的:(牛客网:读入一个字符串str,输出字符串str中的连续最长的数字串)