Lab Letter Name CSE 110 Lab 3 objects and Classes in Java La

Lab Letter: Name: CSE 110 Lab 3: objects and Classes in Java Lab Exercise: Complete this portion of the lab during your labsession. 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 java Test several methods for manipulating String objects import j util Scanner: ava public class StringManips public static void main (String t) args) String phrase new String (\"Programming is fun int phrase Length number of characters in the phrase string int middle Index index of the middle character in the String string first Half: first half of the phrase string String second alf: second half of the phrase String string switchedPhrase: a new phrase with original halves switched compute the length and middle index of the phrase phrase Length phrase length Statement 1 middle Index phraselength 2: get the substring for each half of the phrase first Half phrase -substring (0,middleIndex Statement 2 second half phrase .substring (middle Index, phrase Length) statement 3 catenate the f at the end of the secondHalf switched Phrase secondEalf. concat (firstHalf) Statement 4 prin informatio about the ph

Solution

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.

 Lab Letter: Name: CSE 110 Lab 3: objects and Classes in Java Lab Exercise: Complete this portion of the lab during your labsession. 1. String Manipulation: The

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site