测试1

package DEMO01;

import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一句话,如果包含wqnmlgb,ndy,dsb等字符,将会被和谐");
        String word = sc.next(); //获取用户输入
        //创建关键字和谐数组
        String[] strings = {"wqnmlgb", "ndy", "dsb"};
        //遍历数组,判断用户输入是否包含关键字
        for (int i = 0; i < strings.length; i++) {
            //如果包含关键字,就用星号替换掉
            if (word.contains(strings[i])) {
                word = word.replace(strings[i], "*****");
            }
        }
        System.out.println("你输入的是: " + word);
    }


}

 

posted @ 2019-08-11 20:44  HxTZzz  阅读(130)  评论(0编辑  收藏  举报