Java基础—消除敏感字并替换逻辑

Java代码

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HeXieWenZi {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        List<String> list=new ArrayList<>();
        list.add("血腥");
        list.add("暴力");

        List<WenZi> list1=new ArrayList<>();
        for (int i=0;i<list.size();i++){
            WenZi wenZi=new WenZi();
            wenZi.setWenZi(list.get(i));
            wenZi.setIndex(list.get(i).length());
            list1.add(wenZi);
        }
        System.out.println("请输入你要执行的语句");
        String next = scanner.next();

        if(list.size()!=0){
            char[] c=next.toCharArray();
            for (int k=0;k<next.length();k++){
                for (int h=0;h<list1.size();h++){
                    char[] f=list1.get(h).getWenZi().toCharArray();
                    if (f[0]==(c[k])){
                        int index=0;
                        int start=k;
                        for (int j=0;j<list1.get(h).getIndex();j++){
                            if (c[start]==f[j]){
                                index++;
                                start++;
                            }
                        }
                        if (index==list1.get(h).getIndex()){
                            for (int l=0;l<list1.get(h).getIndex();l++){
                                c[k+l]='*';
                            }
                            k+=list1.get(h).getIndex()-1;
                        }
                    }
                }
            }
            System.out.println(c);
        }else {
            System.out.println(next);
        }
    }
}
class WenZi{

    public String getWenZi() {
        return wenZi;
    }

    public void setWenZi(String wenZi) {
        this.wenZi = wenZi;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    private String wenZi;
    private int index;
}
上一篇:.Net下使用 Geb.Video.FFMPEG 操作视频文件


下一篇:一分钟让你快速了解红外气体传感器作用,特性及应用