Answered step by step
Verified Expert Solution
Question
1 Approved Answer
StringLab StringLab BACKGROUND A String in Java is very important, because many of the opportunities that capture user input include a String. For us, a
StringLab StringLab BACKGROUND A String in Java is very important, because many of the opportunities that capture user input include a String. For us, a String is the first exposure to classes and objects in Java. Unlike primitive data types which just hold data, objects can perform different tasks with the data they hold. For instance, a Suriny can convert itself to all uppercase (or lowercase). It can also trim all the leading and trailing whitespace from it. It can report its length (number of characters). It can see if specific characters are contained in it. There are many things that a String can do - check out the Relevant API for more functionality. WALKTHROUGH This software has two phases: STEP 1: Obtain input from the user Prompt the user for a phrase and store their input into a string. Also prompt the user for a character and store it in a variable of type char STEP 2: Output result of various String methods used on the input Use the length() method, the charAt() method, and the indexOf() method to match the output seen in the Sample Output SPECIFICATIONS CLASS NAME: Stringlah Pay particular attention to the formatting - the output on the screen should look identical to the output in the sample output. The sample output relies on the String "this is a best", so the sample output may use 14 to represent the length of the String. Those numbers are based on the input from the user. If the String had been, "Sweeney Todd", then number for length would be 12 NOTES The phrase for this example is "this is a test". Note that when the program is graded, the phrase may be something else, so make sure that the software is not hard-coded to support only one phrase (see Sample Output for more examples). There is no read Chal method in Scanner, so you will have to adapt. Consider the following code that takes in a string and casts the first character in that String as a char: char character = scanner nextLine).charAt(0); This will use the Scanner to get the input as a String and then chain the charAt() method to it to grab the first character in the String Please enter a phrase: this is a test Please enter a character to search for: The length of your String is 14 The character in the first position is '. The character in tbe last position is 'I'. The first occurrence of win in position 12. =======
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