Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab Letter: Name: CSE 110 Lab 3: Objects and Classes in Java Lab Exercise: Compl

ID: 3786996 • Letter: L

Question

Lab Letter: Name: CSE 110 Lab 3: Objects and Classes in Java Lab Exercise: Complete this portion of the lab duringyourlab ssion. 1. String Manipulation: The following program illustrates the use of some of the methods in the String class. Study the program to see what it is doing. String Manips Test several methods for manipulating String objects import java .util. Scanner: public class StringManips public stat void main (stringt) args) string phrase new string Programming is fun. int phrase Length; number of characters in the phrase string middle Index index of the middle character in the String string firsthalf first half of the phrase string string second half the string switched switched new phrase with original halves hrase: compute the and middle index of the phrase phraselength phrase length statement 1 middleIndex hraselength 2; get the substring for each half of the phrase Statement 2 first Ealf a phrase. substring (0,middleIndex) statement 3 Ralf phrase, substring (middleIndex phrase Length) second concatenate the firsthalf the end of the secondlalt 4 switchedPhrase secondlalt. concat (first Hals): statement Print information about the phrase

Explanation / Answer

Problem-1:

Statement 1 is calculating number of characters stored in String phrase(which is 19) and assigning that number to integer variable phraseLength.

Statement 2 is storing the first half of the String phrase (which is "Programmi") in the String firstHalf by using substring method having index from 0 to middleIndex-1 (which is 9-1 i.e., 8).

Statement 3 is storing the second half of the String phrase (which is "ng is fun.") in the String secondHalf by using substring method having index from middleIndex to phraseLength-1.

Statement 4 is concating two strings secondHalf (which is "Programmi") and firstHalf (which is "ng is fun.") and storing concated string in String switchedPhrase (which is "ng is fun.Programmi").

Statement 5 is printing the character at the middleIndex i.e., the character at index 9 in String phrase. It outputs the following statement at the console:

Character at the middle index: n

Hope it helps, do give your response.