测试1---输入一串字符,并和谐掉

 1 package com.review;
 2 
 3 import java.util.Scanner;
 4 
 5 /**
 6  * @program: com.review
 7  * @description:
 8  * @author: Mr.Lin
 9  * @create: 2019年8月13日
10  **/
11 public class Quiz {
12     static Scanner sc = new Scanner(System.in);
13     public static void main(String[] args) {
14         System.out.println("输入一句话,包含wqnmlgb,ndy,dsb等字符,将会被和谐");
15         String character = sc.next(); //获取用户输入
16         //创建关键字和谐数组
17         String characters[] = {"wqnmlgb","ndy","dsd"};
18         //遍历数组,判断用户是否输入关键字
19         for(int i=0;i<characters.length;i++) {
20             //如果包含关键字,就用*替换
21             if(character.contains(characters[i])) {
22                 character = character.replace(characters[i], "***");
23             }
24         }
25         System.out.println("你输入的是"+character);
26     }
27 }
View Code

原文地址:https://www.cnblogs.com/lpbk/p/11346136.html