题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); String str = sc.nextLine(); char[] arr = str.toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { if (Character.isDigit(arr[i]) == false) { sb.append(arr[i]); } else { if (i == 0 || Character.isDigit(arr[i - 1]) == false) { sb.append("*" + arr[i]); } else { sb.append(arr[i]); } if (i == arr.length - 1 || Character.isDigit(arr[i + 1]) == false) { sb.append("*"); } } } System.out.println(sb.toString()); } }