Question
a) Write a main( ) method that declares a String reference variable. b) Read a sentence (with spaces) using keyboard input. Create a String object
a) Write a main( ) method that declares a String reference variable.
b) Read a sentence (with spaces) using keyboard input. Create a String object using this input. Input a sentence that is long enough and has enough letters to accomplish each of the following tasks.
c) Write the String method calls and print the output for each of these tasks. Note that some of these cannot be written with one line of code and one String class method call.
a. Print the number of characters your sentence contains. b. Print the first letter of your sentence c. Print the last letter of your sentence d. Print whether your sentence contains the letter e e. Print whether your sentence contains ay or not. f. Print the number of times the letter e appears in your sentence g. Find the position of the last occurrence of the letter e in your sentence h. Find the position of the second occurrence of the letter e in your sentence i. Print how many characters your sentence contains without the space character. j. Add the words you know to the sentence k. Print a completely upper case version of your sentence l. Extract and print a substring of five characters from your sentence m. Print a String where all the chars a are replaced with the char x
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