ed erinput is "Dang, that was that was scary! Che submitted code has a n end never reached." The
ed erinput is "Dang, that was that was scary! Che submitted code has a n end never reached." The
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![**Title: Understanding String Operations in Java**
**Objective:**
The purpose of this instructional guide is to demonstrate a Java program that censors specific words from user input.
---
**Task:**
Print "Censored" if `userInput` contains the word "darn", otherwise print `userInput`. Ensure the output concludes with a newline character.
**Example:**
- If `userInput` is "That darn cat.", the output is:
```
Censored
```
- If `userInput` is "Dang, that was scary!", the output is:
```
Dang, that was scary!
```
**Important Note:**
If the submitted code accesses an out-of-range index, the system will cease execution, reporting "Program end never reached." The system does not reveal the test case leading to this report.
**Java Program Example:**
```java
import java.util.Scanner;
public class CensoredWords {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userInput;
userInput = scnr.nextLine();
if (userInput.indexOf("darn") != -1) {
System.out.println("Censored");
}
else {
System.out.println(userInput);
}
}
}
```
**Explanation:**
- The program reads a line of text from the user.
- It checks if the input contains the substring "darn" using the `indexOf` method.
- If the substring is found, "Censored" is printed.
- If not, the original user input is displayed.
- The code passes a test when the expected output matches the result.
This instructional content helps learners understand basic string manipulation and condition checking in Java efficiently.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F140c7626-2888-4935-8928-dcb55a4fc57b%2F1391fdd4-7579-46fc-88ac-b55e3fdb4ea5%2Fgsayfz_processed.png&w=3840&q=75)
Transcribed Image Text:**Title: Understanding String Operations in Java**
**Objective:**
The purpose of this instructional guide is to demonstrate a Java program that censors specific words from user input.
---
**Task:**
Print "Censored" if `userInput` contains the word "darn", otherwise print `userInput`. Ensure the output concludes with a newline character.
**Example:**
- If `userInput` is "That darn cat.", the output is:
```
Censored
```
- If `userInput` is "Dang, that was scary!", the output is:
```
Dang, that was scary!
```
**Important Note:**
If the submitted code accesses an out-of-range index, the system will cease execution, reporting "Program end never reached." The system does not reveal the test case leading to this report.
**Java Program Example:**
```java
import java.util.Scanner;
public class CensoredWords {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
String userInput;
userInput = scnr.nextLine();
if (userInput.indexOf("darn") != -1) {
System.out.println("Censored");
}
else {
System.out.println(userInput);
}
}
}
```
**Explanation:**
- The program reads a line of text from the user.
- It checks if the input contains the substring "darn" using the `indexOf` method.
- If the substring is found, "Censored" is printed.
- If not, the original user input is displayed.
- The code passes a test when the expected output matches the result.
This instructional content helps learners understand basic string manipulation and condition checking in Java efficiently.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education