1.设计一个敏感词过滤程序
public class Word { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入:"); String word = scanner.nextLine(); String arr=sear(word); System.out.println(arr); } public static String sear(String work){ String[] arr1 = {"死","枪","共产党"}; for (int i = 0; i < arr1.length; i++) { work = work.replace(arr1[i],"*"); } return work; } }
运行结果:
2.国庆倒计时