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