2. Write a program that will be used to experiment with methods of the String cl
ID: 3749803 • Letter: 2
Question
2. Write a program that will be used to experiment with methods of the String class. In this program, defin the following Strings using the identifier names below and include the initial values as shown below Identifier Name Initial Value telephoneNumber 5554545 initialStringValue "A String is an array of characters morelnformation concatenated String When defining the telephoneNumber variable use a String constructor with some built in methods Using the variables defined above, perform the following tasks to the console in the format "555-4545 1. Print 2. Convert telephone number to an integer and store the result FS F6 F7 F8 F9 F11 PrSk BreakExplanation / Answer
This program has been done using python
if __name__ == '__main__':
//Declaration as per given question
telephoneNumber=5554545;
initialStringValue='A string is an array of characters';
moreInformation=', with some built in methods';
concatenatedString='';
//Converting integer into list to seperate each number
listNumber=list(str(telephoneNumber));
//now first 2 number join with '-' and other remaining number
splitNumber=''.join(listNumber[0:2])+"-".join(listNumber[2:4])+''.join(listNumber[4:]);
Question1 //Now print telephone number
print("Telephone Number: " + splitNumber);
Question3//print length of initalstringvalue. len is use to find the length and str is use to convert the int value into string
print("InitialStringvalue length is: "+str(len(initialStringValue)));
//now for concatenation just use '+' and store value into 3rd variable
concatenatedString=initialStringValue+moreInformation;
Question4 //print concatenated string
print("ConcatenatedString "+concatenatedString);
Question5 //print length of concatenated string. len is use to find length of string
print("concatenated length is: "+str(len(concatenatedString)));
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.