标签:scribe static esc boolean int string sub false str
将一个字符中所有出现的数字前后加上符号“*”,其他字符保持不变
示例1:
Jkdi234klowe90a3
Jkdi*234*klowe*90*a*3*
private static void markNum(String str) {
StringBuilder result = new StringBuilder();
boolean isFrist = true;
for (char c : str.toCharArray()) {
boolean isNum = ‘0‘ <= c && ‘9‘ >= c;
if(isNum && isFrist){
result.append("*").append(c);
isFrist = false;
}else {
result.append(c);
if(!isNum){
isFrist = true;
}
}
}
System.out.println(result);
}
标签:scribe static esc boolean int string sub false str
原文地址:https://www.cnblogs.com/dongma/p/13232884.html