
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: Intro Obj Orient Programming; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Fall 2005;
Typology: Lab Reports
1 / 1
This page cannot be seen from the preview
Don't miss anything!

File CountLetters.java contains a program that reads a word from the user and prints the number of occurrences of each letter in the word. Save it to your C:\TEMP directory and study it, then compile and run it to see how it works.
In reading the code, note that the word is converted to all upper case first, then each letter is translated to a number in the range 0..25 (by subtracting ' A ') for use as an index. No test is done to ensure that the characters are in fact letters.
Since you want don't want to do anything when a non-letter occurs, the catch will be empty.
Modify this method to do this as follows:
Put the body of the first for loop in a try. Add a catch that catches the exception, but don't do anything with it.
Compile and run your program.