Ask Question

Print "Censored" if userInput contains the word "darn", else print userInput. End with newline. Ex: If userInput is "That darn cat.", then output is:

Censored

Ex: If userInput is "Dang, that was scary!", then output is:

Dang, that was scary!

Note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.

#include

#include

using namespace std;

int main () {

string userInput;

getline (cin, userInput);

int isPresent = userInput. find ("darn");

if (isPresent > 0) {

cout << "Censored" << endl; / * Your solution goes here * /

return 0;

}

+2
Answers (1)
  1. 27 September, 16:59
    0
    The Java code is given below

    Explanation:

    import java. util.*;

    public class CensoredWords {

    public static void main (String args[]) {

    Scanner scnr=new Scanner (System. in);

    String userInput;

    System. out. println ("Enter String: ");

    userInput=scnr. nextLine ();

    int res=userInput. indexOf ("darn");

    if (res = = - 1) {

    System. out. println (userInput);

    } else {

    System. out. println ("Censored");

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Print "Censored" if userInput contains the word "darn", else print userInput. End with newline. Ex: If userInput is "That darn cat.", then ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers