Question
In this project, you will explore the String class and learn how to use its various methods to manipulate strings. Task 1: Create a Java
In this project, you will explore the String class and learn how to use its various methods to manipulate strings.
Task 1: Create a Java program that prompts the user for a string and then uses the length() method to determine the length of the string. Print the length of the string to the console.
Task 2: Use the concat() method to concatenate the two strings. Print the resulting string to the console.
Task 3: Prompt the user for a string and then uses the substring() method to extract a portion of the string. Prompt the user for the starting index and ending index of the portion of the string to extract, and then print the extracted portion of the string to the console.
Task 4: Prompt the user for a string and then uses the toLowerCase() and toUpperCase() methods to convert the string to lowercase and uppercase, respectively. Print the lowercase and uppercase versions of the string to the console.
Task 5: Prompt the user for a string and then uses the charAt() method to determine the character at a specified index in the string. Prompt the user for the index and then print the character at that index to the console.
Task 6: Prompt the user for a string and then uses the indexOf() method to find the index of the first occurrence of a specified character in the string and then print the character at that index to the console.
Task 7: Prompt the user for a string and then uses the replace() method to replace all occurrences of a specified character in the string with another character. Prompt the user for the character to replace and the character to replace it with, and then print the modified string to the console.
Task 8: Prompt the user for a string and then uses the trim() method to remove leading and trailing whitespace from the string. Print the modified string to the console.
Task 9: Prompt the user for a string and then uses the split() method to split the string into an array of strings based on a specified delimiter. Prompt the user for the delimiter and then print the resulting array of strings to the console.
Task 10: Prompt the user for a string and then uses the startsWith() and endsWith() methods to determine if the string starts with a specified prefix and ends with a specified suffix, respectively. Prompt the user for the prefix and suffix and then print the results to the console.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started