Java Program: PX_Substring3Words_lastname

Specification Sheet

Program Name:
SubstringDemo

Description:
The program allows users to extract specific portions of a string using Java's substring method. Users can choose to extract:

Input:
- A full string (e.g., 'Hello, welcome to Java programming').
- Start and end indices (if extracting a middle portion).

Output:
- Extracted substring based on the chosen operation.

Pseudo Code

1. Start
2. Accept a string from the user.
3. Display a menu with options:
   - Extract the first word.
   - Extract a middle portion.
   - Extract the last word.
4. Based on the user's choice:
   - Use `substring` to extract the desired portion:
     - For the first word: Find the first space index and extract from 0 to that index.
     - For the middle portion: Prompt the user for start and end indices.
     - For the last word: Find the last space index and extract from there to the end.
5. Display the extracted substring.
6. End
    

Java Code

Example Execution

Input:
Enter a string:
Hello, welcome to Java programming
Choose an option:
1. Extract the first word
2. Extract a middle portion
3. Extract the last word

Output (for each choice):
- Option 1: First word: Hello,
- Option 2: (User inputs start = 7, end = 14) Middle portion: welcome
- Option 3: Last word: programming

Google Classroom

• Your files will be:
• PX_Substring3Words_lastname.java (java program)
• PX_Substring3Words_lastname.png (Screen print)
• PX_Substring3Words_lastname.mp4 (video of you running your program)
• Drop off all 3 files into google classroom.