12345678910111213141516171819202122232425262728293031 |
- package J20250715.testString;
- import java.util.Scanner;
- /**
- * @author WanJl
- * @version 1.0
- * @title Demo02
- * @description 案例:敏感词替换
- * @create 2025/7/15
- */
- public class Demo02 {
- /*
- 需求:
- 键盘输入一个字符串,其中字符串包含(TMD),则使用***替换
- 实现步骤:
- 1、键盘录入一个字符串,用Scanner实现
- 2、替换敏感词
- replace(CharSequence target, CharSequence replacement)方法
- replace("","")
- 把当前字符串中的指定的内容替换为新的字符串
- 3、输出结果
- */
- public static void main(String[] args) {
- System.out.println("请输入一段字符串...");
- Scanner sc=new Scanner(System.in);
- String s = sc.nextLine();
- String result = s.replace("TMD", "***");
- System.out.println(result);
- }
- }
|