Practice Programs
Practice Programs can generally be solved with a short program that directly applies the programming principles presented in this chapter.
Use the exception class
MessageTooLongExceptionof Self-Test Question 16 in a program that asks the user to enter a line of text having no more than 20 characters. If the user enters an acceptable number of characters, the program should display the message, “You entered x characters, which is an acceptable length” (with the letter x replaced by the actual number of characters). Otherwise, aMessageTooLongExceptionshould be thrown and caught. In either case, the program should repeatedly ask whether the user wants to enter another line or quit the program.A method that returns a special ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access