题解 | #表示数字#
表示数字
http://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
for
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc =new Scanner(System.in);
while(sc.hasNextLine()) {
String str = sc.nextLine();
String str1 = str.replaceAll("[0-9]", "");
if (str1.length() == 0) {
System.out.println("*"+str+"*");
continue;
}
StringBuilder sb = new StringBuilder();
for (int i =0; i < str.length(); i++) {
char a = str.charAt(i);
if (a >= '0' && a <= '9') {
sb.append("*");
for (int j = i; j < str.length(); j++) {
char b =str.charAt(j);
i = j;
if (b < '0' || b > '9') {
sb.append("*");
sb.append(b);
break;
}
sb.append(b);
}
} else {
sb.append(a);
}
}
char l = str.charAt(str.length() - 1) ;
if (l >= '0' && l <= '9') {
sb.append("*");
}
System.out.println(sb.toString());
}
}
}