Java写题解的第5天 | #表示数字#
表示数字
http://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
解题思路:模拟,遍历
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = ""; while ((s = br.readLine()) != null) { StringBuilder sb = new StringBuilder(); int index = 0; while (index < s.length()) { if (Character.isDigit(s.charAt(index))) { sb.append('*'); while (index < s.length() && Character.isDigit(s.charAt(index))) { sb.append(s.charAt(index)); index++; } sb.append('*'); } else { sb.append(s.charAt(index)); index++; } } System.out.println(sb.toString()); } br.close(); } }