Ask Question
12 October, 06:40

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. 12 October, 08:47
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers