题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.useDelimiter("\n"); while (scanner.hasNext()) { String S = scanner.next(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < S.length();) { if (S.charAt(i)>='0' && S.charAt(i) <= '9') { builder.append("*"); builder.append(S.charAt(i)); int j=i+1; while (j<S.length()) { if (!(S.charAt(j)>='0' && S.charAt(j) <= '9')) { break; } builder.append(S.charAt(j)); j++; } builder.append("*"); i=j; } else { builder.append(S.charAt(i)); i++; } } System.out.println(builder); } } }