Question: Java String and Loop question So I'm writing this program which prompts user to enter a paragraph and the specific word that they want to
Java String and Loop question
So I'm writing this program which prompts user to enter a paragraph and the specific word that they want to censor and eventually output the censored paragraph. How to sensor the wanted word only? Here, it censors whatever letter that appears in the word which needed to be censored.
For example:
Paragraph: Apple is a type of fruit
word needed to be censored with *: apple
Output: ***** is a type of fruit


public class Randomt public static void main(String[largs) f Scanner input = new Scanner(System.in); System.out.println("Please enter the paragraph you would like filtered: "); String paragraph input.nextLine); System.out.println("Please enter the word you would like to censor: "); String word 1nput.nextLine(); System.out.println("Uncensored:") System.out.println(paragraph); paragraph = paragraph. toLowerCase(); word = word, toLowerCase(), trim(); { (int i= 0; paragraph = paragraph. replace(String.valueOf(word. charAt(i)), for iaord. length(); i++) replacement: "x"); System.out.println("Censored: "paragraph)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
