import java.util.Scanner;
public class Holle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入自定义敏感词:");
String senSc = sc.nextLine(); //输入敏感词
System.out.println("敏感词为:" + senSc);
int count = senSc.length(); //存放敏感词字符串长度
String rep_senSc = ""; //定义新字符串
for (int i = 0; i < count; i++){
rep_senSc += "*"; //赋值 敏感词长度的 * 给新字符串
}
System.out.print("请输入字符串:");
String str = sc.nextLine(); //样例输入
if(str.contains(senSc)){ //是否含有敏感词
String new_str = str.replace(senSc, rep_senSc); //替换
System.out.println(new_str); //输出新字符串
}else{
System.out.println("无敏感词");
}
}
}
屏蔽敏感词
最新推荐文章于 2022-12-16 19:31:45 发布