0% found this document useful (0 votes)
3 views4 pages

String Manipulation and Processing Guide

The document outlines four practice problems focused on string creation, manipulation, input processing, and management using Java. Each problem includes tasks such as creating strings through various methods, processing user input, managing student names with string arrays, and developing a text processor. The problems are designed to reinforce concepts related to string handling and manipulation in programming.

Uploaded by

as3929
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

String Manipulation and Processing Guide

The document outlines four practice problems focused on string creation, manipulation, input processing, and management using Java. Each problem includes tasks such as creating strings through various methods, processing user input, managing student names with string arrays, and developing a text processor. The problems are designed to reinforce concepts related to string handling and manipulation in programming.

Uploaded by

as3929
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🛠️ PRACTICE PROBLEM 1:

String Creation and Manipulation


Task: Create a program that demonstrates different ways to create strings and basic
manipulation.

public class StringManipulation{​


public static void main(String[] args) {​
// TODO: Create the same string "Java Programming" using 3
different methods:​
// 1. String literal​
// 2. new String() constructor​
// 3. Character array​

// TODO: Compare the strings using == and .equals()​
// Print the results and explain the difference​

// TODO: Create a string with escape sequences that displays:​
// Programming Quote:​
// "Code is poetry" - Unknown​
// Path: C:\Java\Projects​
}​
}

🛠️ PRACTICE PROBLEM 2:
String Input and Processing
Task: Create a program that takes user input and processes it using various string methods.

import [Link];​

public class StringMethods{​

1
public static void main(String[] args) {​
Scanner scanner = new Scanner([Link]);​

// TODO: Ask user for their full name (first and last name)​
// TODO: Ask user for their favorite programming language​
// TODO: Ask user for a sentence about their programming experience​

// TODO: Process the input:​
// 1. Extract first and last name separately​
// 2. Count total characters in the sentence (excluding spaces)​
// 3. Convert programming language to uppercase​
// 4. Display a formatted summary​

[Link]();​
}​
}

🛠️ PRACTICE PROBLEM 3:
String Arrays and Methods
Task: Create a program that manages a list of student names using string arrays and methods.

public class StringArrays {​



// TODO: Create a method that takes a string array of names​
// and returns the longest name​
public static String findLongestName(String[] names) {​
// Your code here​
}​

// TODO: Create a method that counts how many names​
// start with a given letter (case-insensitive)​
public static int countNamesStartingWith(String[] names, char letter) {​
// Your code here​
}​

2

// TODO: Create a method that formats all names to "Last, First" format​
// Assume names are given as "First Last"​
public static String[] formatNames(String[] names) {​
// Your code here​
}​

public static void main(String[] args) {​
String[] students = {"John Smith", "Alice Johnson", "Bob Brown",
"Carol Davis", "David Wilson"};​

// TODO: Test all your methods and display results​
}​
}

🛠️ PRACTICE PROBLEM 4:
Complete String Application (10 minutes)
Task: Create a simple text processor that combines all concepts learned.

import [Link];​

public class TextProcessor{​

// TODO: Method to clean and validate input​
public static String cleanInput(String input) {​
// Remove extra spaces, convert to proper case​
// Return cleaned string​
}​

// TODO: Method to analyze text​
public static void analyzeText(String text) {​
// Count: words, sentences, characters​
// Find: longest word, most common character​
// Display statistics​

3
}​

// TODO: Method to create word array and sort alphabetically​
public static String[] getWordsSorted(String text) {​
// Split text into words, remove punctuation, sort​
// Return sorted array​
}​

public static void main(String[] args) {​
Scanner scanner = new Scanner([Link]);​

// TODO: Create a text processor that:​
// 1. Asks user for a paragraph of text​
// 2. Cleans and validates the input​
// 3. Analyzes the text (word count, character count, etc.)​
// 4. Shows the words in alphabetical order​
// 5. Allows user to search for specific words​

[Link]("=== TEXT PROCESSOR ===");​
// Your implementation here​

[Link]();​
}​
}

You might also like