Advertisement
deyanmalinov

04. Text Filter

Mar 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.         public static void main(String[] args) {
  7.             Scanner scan = new Scanner(System.in);
  8.             String [] banWords = scan.nextLine().split(", ");
  9.             String line = scan.nextLine();
  10.  
  11.             for (String word : banWords) {
  12.                 if (line.contains(word)){
  13.                     String newStr = replace("*", word.length());
  14.                     line = line.replace(word, newStr);
  15.                 }
  16.             }
  17.             System.out.println(line);
  18.         }
  19.         public static String replace (String text, int count){
  20.             String res = "";
  21.             for (int i = 0; i < count; i++) {
  22.                 res += text;
  23.             }return res;
  24.         }
  25. //        for (String word : banWords) {
  26. //            String stars = word.replaceAll(".", "*");
  27. //            line = line.replace(word, stars);
  28. //        }
  29. //        System.out.println(line);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement