Ask Question
19 November, 08:42

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;

}

+4
Answers (1)
  1. 19 November, 12:41
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers