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
icon
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
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
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education