public class ShowsNum { public Map getNums(String str){ HashMap<Integer,String> map=new HashMap<Integer,String>(); char [] chnum=str.toCharArray(); StringBuffer strbuffer=new StringBuffer(); int des=1; for(int i=0;i<chnum.length;i++){ //当前字符是数字 if(chnum[i]-‘0‘>=0&&chnum[i]-‘0‘<=9){ strbuffer.append(chnum[i]); //判断下一个字符不是数字 //判断;临界点 if((i+1)==chnum.length){ map.put(des, new String(strbuffer)); break; } if(!(chnum[i+1]-‘0‘>=0&&chnum[i+1]-‘0‘<=9)){ map.put(des, new String(strbuffer)); des++; strbuffer=strbuffer.delete(0,strbuffer.length()); } } } return map; } }
输入字符串取出字符串中的连续数字放入单独数组
时间: 2024-10-12 20:58:23