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
MessageTooLongException
of 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, aMessageTooLongException
should 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 ...
Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.