1. Engineering
  2. Computer Science
  3. this is a sample transcript of what your program should...

Question: this is a sample transcript of what your program should...

Question details

This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program.

Please assign the integer to the length and keyboard.nextLine

and do not use redline and sc.nextLine

Thank you so much

Enter a long string: The quick brown fox jumped over the lazy dog
Enter a substring: jumped
Length of your string: 44
Length of your substring: 6
Starting position of your substring in string: 20
String before your substring: The quick brown fox
String after your substring: over the lazy dog
Enter a position between 0 and 43: 18
The character at position 18 is x
Enter a replacement string: leaped
Your new string is: The quick brown fox leaped over the lazy dog

Your program should work for any arbitrary string and substring. Here's another sample transcript of a different execution of the same code:

Enter a long string: Friends, Romans, countrymen, lend me your ears
Enter a substring: try
Length of your string: 46
Length of your substring: 3
Starting position of your substring in string: 21
String before your substring: Friends, Romans, coun
String after your substring: men, lend me your ears
Enter a position between 0 and 45: 21
The character at position 21 is t
Enter a replacement string: catch
Your new string is: Friends, Romans, councatchmen, lend me your ears

NOTE: Be careful when reading a String value from your Scanner after reading an integer value. After reading an integer value you must read an empty line using the nextLine() method before you read a String from the Scanner.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution