题解 | #表示数字#for循环逐一判断
表示数字
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); while (in.hasNext()) { String str = in.next(); int flag = 0; for (int i = 0; i < str.length(); i++) { if (Character.isDigit(str.charAt(i)) && flag == 0) { System.out.print("*"); flag = 1; } if (!Character.isDigit(str.charAt(i)) && flag == 1) { System.out.print("*"); flag = 0; } System.out.print(str.charAt(i)); } if (Character.isDigit(str.charAt(str.length() - 1))) { System.out.print("*"); } } } }