题解 | #表示数字#
表示数字
http://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
/**
* @author eagle2020
* @date 2021/9/29
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str;
while((str = reader.readLine()) != null){
StringBuilder sb = new StringBuilder();
boolean lastDigit = false;
int len = str.length();
for(int i = 0; i < len; i++){
char c = str.charAt(i);
if(c >='0' && c <= '9'){
if(!lastDigit){//之前不是数字
sb.append("*");
}
sb.append(c);
lastDigit = true;
}else{//字母
if(lastDigit){//上一个是数字
sb.append("*");
}
sb.append(c);
lastDigit = false;
}
}
if(lastDigit){
sb.append("*");
}
System.out.println(sb);
}
}
}