0% found this document useful (0 votes)
479 views2 pages

Java String Practice Worksheet

Uploaded by

api-333836093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
479 views2 pages

Java String Practice Worksheet

Uploaded by

api-333836093
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
JAVA STRINGS Let String 1 = “The quick brown fox jumps over the lazy dogs.” Let String 2 = “Mississippi” Let String 3 = “Your Name” Enter your first and last name. Let String 4 = “mississippi” EXERCIS! 1) Write an appropriate java program that will: a. Retum the length of the 4 strings. b. Compare String? with Strings and determine if they are the same. ¢c, Compare String? with String 4 ignoring case and determine if they are the same. d e Convert Stings 1, 2, 3, and 4 to all upper case letters. . Convert Strings 1, 2, 3, and 4 to all lower case letters. 2) Restore strings 1 to 4 to their original values. Find the character at index position 6 in each string. (Put your guess first in the lines below and then check by writing the appropriate Java code.) Index position 6 for: String 1: String 2: String 3: String 4: Determine what will be returned by charAt(3) and charAt(9) for each of the 4 Strings. Write your answers first and then check by using the appropriate Java code. charAt(3) String]: String? String3: Strings: charAt(9) String’ String? String3: Strings: 3) Use the appropriate method .coneat(String s), create two new strings, StringS and String 6 that append String? to String! (for new StringS) and and String4 to String 3. (New String6) Show the results below. String 5), String 6) 4) Using the .replace(char oldChar, char newChar) method, replace every s character in each of the strings with az, Write the results below. String]: String: String2: String: 5) Restore the strings one through 4 to their original values. Using the substring(int start, int end) method, list the substrings returned for each of the four strings if the values of (0, 4) and (3,8) are used. Write down what you think should ‘appear first and then check by programming the appropriate Java commands and check. Substring (0,4) String] String? String3: String4: Substring(3,8) String! String?, String3:

You might also like