Ask Question

Print "Censored' if userlnput contains the word "darn, else print userlnput. End with newline. Ex: If userinput is "That darn cat., then output is: Censored Ex: If userlnput 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. 1 import java. util. Scanner; 3 public class CensoredWords 4public static void main (1 test passed String args) Scanner scnr - new Scanner (System. in); String userInput; A tests passed userInput scnr. nextLine); 10 Your solution goes here 12 13 Run

+2
Answers (1)
  1. 12 January, 22:54
    0
    The code is given below in Java with appropriate comments

    Explanation:

    //Import the input.

    import java. util. Scanner;

    class CensoredWords

    {

    //Define the main method.

    public static void main (String args[ ])

    {

    //Define the variables.

    String userInput="";

    //Define the scanner object

    Scanner scobj = new Scanner (System. in);

    //Accept the userInput.

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

    userInput=scobj. nextLine ();

    //Check if the input contains darn.

    //Print censored.

    if (userInput. toUpperCase (). indexOf ("DARN") ! = - 1)

    System. out. printf ("Censored");

    //IF the input does not contains darn

    //Print userInput.

    else

    System. out. printf (userInput)

    return;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Print "Censored' if userlnput contains the word "darn, else print userlnput. 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