Java双重循环实现任意字符串中提取数字子串

mac2022-06-30  95

public class Test2{  public static void main(String[] args) {   String s = "211ahn678rh2kkk07312n3e12w4";   int begin = 0;   outer:for(;begin<s.length();){    if(!(s.charAt(begin)>=48 && s.charAt(begin)<=57)){     begin++;     continue;    }    int end = begin;    for(;end<s.length();){     if(!(s.charAt(end)>=48 && s.charAt(end)<=57)){      System.out.println(s.substring(begin,end));      begin = end;      break;     }else{      end++;      if(end == s.length()){       System.out.println(s.substring(begin));       break outer;      }else{       continue;      }     }    }   }  } }

转载于:https://www.cnblogs.com/iamconan/p/7383611.html

最新回复(0)