So far, you probably haven’t seen many run-time errors, because we haven’t been doing many things that can cause one. Well, now we are. If you use the [] operator and you provide an index that is negative or greater than length-1, you will get a run-time error and a message something like this:
Listing7.6.1.Running this active code will result in a runtime error. Can you fix it so that we print out the first letter and last letter of string greeting instead of indexing out of range?
Construct a block of code that correctly changes the string to say “cat in the hat” instead of “cat on the mat”, then print it. Change the necessary characters in order from index 0 to the end of the string.