Print “censored” if userinput contains the word “darn”. else print userinput. end with newline.

(Java Zybooks) Print “Censored” if userInput offers the term
“darn”, else printing userInput. End with newline. Ex: If userInput is
“That darn pet.”, after that production is: Censored
Ex: If userInput is “Dang, which was frightening!”, after that production is: Dang, which was frightening!
Note: If presented signal has actually an out-of-range accessibility, the
system stop operating the signal after a matter of seconds, and report
“system end never ever achieved.” The machine does not print the test situation
that caused the stated message. import java.util.Scanner; general public course CensoredWords {
general public fixed void primary (String [] args) {
Scanner scnr = brand new Scanner(System.in);
String userInput; userInput = scnr.nextLine(); /* Your answer goes right here */ }
}

Note: The altered section of
the signal is highlighted in grey and strong.

Screenshot of this
signal:

Test Production:

Code to duplicate:
//Import needed bundle.
import java.util.Scanner;
//Define the course CensoredWords.
general public course CensoredWords
{
//Start the main() strategy.
general public fixed void primary (String [] args)
{
//Create an item of this course Scanner
course.
Scanner scnr = brand new Scanner(System.in);
//Declare needed factors.
String userInput;
//Prompt the consumer to input a sequence.
userInput = scnr.nextLine();
/* Your answer goes right here */
//Find the list of
sequence darn when you look at the sequence
//userfeedback making use of
the strategy indexOf(). If
//returned price is
maybe not -1, it means
//the term darn is
within the sequence and
//display
censored.

if(userfeedback.indexOf(“darn”)
!= -1)
{

Program.out.println(“Censored”);
}

//Otherwise, show
the sequence userInput with

//newline.
else
{

Program.out.println(userfeedback);
}
}
}
//Import needed bundle. import java.util.Scanner; //Define the course CensoredWords. general public course CensoredWords { //Start the main () method. public static void main (String [] args) { //Create an object of the class Scanner class. new Scanner (System.in); Scanner scnr = /Declare required variables. String userInput; //Prompt the user to input a string. userInput scnr.nextLine (); = Your solution goes here //Find the index of string darn in the string //userInput using the method indexOf (). If the //returned value is not -1, then it means that //the word darn is included in the string and //display censored. != -1) if (userInput.indexOf (“darn”) { System.out.println(“Censored”); } //otherwise, display the string userInput with //newline. else { System.out.println (userInput); } }
I am darning your clothes Censored
(Java Zybooks) 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 doesnt print the test case
that caused the reported message.
import java.util.Scanner;
public class CensoredWords {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userInput; 
userInput = scnr.nextLine();
/* Your solution goes here */
}
} (Java Zybooks) 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 doesnt print the test case
that caused the reported message.
import java.util.Scanner;
public class CensoredWords {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userInput; 
userInput = scnr.nextLine();
/* Your solution goes here */
}
}

Leave a Comment