题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
String str = in.nextLine();
StringBuilder ss = new StringBuilder();
for(int i =0;i<str.length();i++){
int first=0;
if(i>0) first = str.charAt(i-1);
int last = str.charAt(i);
if(i>0&&(((first>='0'&&first<='9'&&(last<'0'||last>'9'))||(last>='0'&&last<='9'&&(first<'0'||first>'9'))))){
ss.append("*");
ss.append(str.charAt(i));
}else if(i==0&&last>='0'&&last<='9'){
ss.append("*");
ss.append(str.charAt(i));
}else ss.append(str.charAt(i));
if(i==str.length()-1&&last>='0'&&last<='9'){
ss.append("*");
}
}
System.out.println(String.valueOf(ss));
}
}
}


