Lab #8
Use this link for the String API (useful methods for this lab).
Methods you might need to use in this lab are: substring, contains, indexOf, replace, replaceAll
- Create two String variables. Assing "The best class ever,,," to the first String, and "and the best dxy ever" to the second string. Use different assignment methods for two strings:
String a = ""; and String b = new String("");
- Concatenate the two strings to each other and assign the resultant string to a new variable called d.
- Print the concatenated string.
- Replace ",,," with ", ".
- Replace "dxy" with "day".
- Add a period to the end of the sentence and print it.
- Ask the user to enter a word and check if the string contains that word. Print "The string contains your word!" if the string contains it, and "The string does not contain your word!" otherwise.
- Capitalize the first character of the second word of the sentence and print the revised sentence.
- Remove every 'r' character from the sentence and print the sentence.
Home exercises:
- See this link for sample programs on basics of Java Strings.
- Repeat step #8 for third word of the sentence.
- Repeat step #8 for last word of the sentence .
- Repeat step #4 without using replace method. You can use indexOf(",,,") and substring method instead.
- Repeat step #5 without using replace method. You can use indexOf(",,,") and substring method instead.
- Receive two words from the user and print which one is occured sooner than the other one in the sentence.