Assume three String variables firstName, lastName, and compa…
Assume three String variables firstName, lastName, and companyName have been declared and assigned values. Write code that prints out the total number of characters in the three String variables. For example, if the variables are initialized as: String firstName = “Elon”;String lastName = “Musk”;String companyName = “SpaceX”; your program prints: 14 Some String methods: Method Return Type Description indexOf(String str) int Returns the index within this string of the first occurrence of the specified substring str. indexOf(String str, int fromIndex) int Returns the index within this string of the first occurrence of the specified substring str, starting at the specified index fromIndex. lastIndexOf(String str) int Returns the index within this string of the last occurrence of the specified substring str. lastIndexOf(String str, int fromIndex) int Returns the index within this string of the last occurrence of the specified substring str, searching backward starting at the specified index fromIndex. substring(int beginIndex) String Returns a new string that is a substring of this string. The substring begins with the character at the specified index beginIndex, and extends to the end of this string. substring(int beginIndex, int endIndex) String Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. length() int Returns the length of this string. toUpperCase() String Returns a new string having the same characters as this string, but with any lowercase letters converted to uppercase. toLowerCase() String Returns a new string having the same characters as this string, but with any uppercase letters converted to lowercase.
Read Details