veronikaaa86

04. Text Filter

Nov 10th, 2021
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package textProcessing;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04TextFilter {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String[] bannedWordsArr = scanner.nextLine().split(", ");
  10. String text = scanner.nextLine();
  11.  
  12. //Linux, Windows
  13. for (String bannWord : bannedWordsArr) {
  14. if (text.contains(bannWord)) {
  15. String replacementWord = repeatString("*", bannWord.length());
  16. text = text.replace(bannWord, replacementWord);
  17. }
  18. }
  19.  
  20. System.out.println(text);
  21. }
  22.  
  23. public static String repeatString (String word, int count) {
  24. String[] repeatArr = new String[count];
  25. for (int i = 0; i < count; i++) {
  26. repeatArr[i] = word;
  27. }
  28.  
  29. return String.join("", repeatArr);
  30. }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment