题解 | #表示数字#
表示数字
http://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String s = sc.nextLine();
StringBuilder sb = new StringBuilder();
//System.out.println(s.replaceAll("([0-9]+)","*$1*"));
for(int i=0;i<s.length();){
char c = s.charAt(i);
if(c>='0'&&c<='9'){
sb.append("*");
while(i<s.length() && s.charAt(i)>='0' && s.charAt(i)<='9'){
//继续遍历i后面的字符串,看是不是继续是数字
sb.append(s.charAt(i++));
}
sb.append("*");
}else{
sb.append(s.charAt(i++));
}
}
System.out.println(sb.toString());
}
}
}