1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
自有实现
public class HJ96 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(showNum(sc.nextLine()));
}
public static String showNum(String str) {
char[] arr = str.toCharArray();
StringBuffer sb = new StringBuffer();
StringBuffer num = new StringBuffer();
boolean flag = false;
for (int i = 0; i < arr.length; i++) {
char c = arr[i];
if (Character.isDigit(c)) {
while (i < arr.length && Character.isDigit(arr[i])) {
num.append(arr[i++]);
}
i--;
flag = true;
} else {
if (flag) {
sb.append("*").append(num).append("*");
flag = false;
num = new StringBuffer();
}
sb.append(c);
}
}
if (Character.isDigit(arr[arr.length - 1])) {
sb.append("*").append(num).append("*");
}
return sb.toString();
}
}