subject

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 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.1. run countletters and enter a phrase, that is, more than one word with spaces or other punctuation in between. it should throw an , because a non-letter will generate an index that is not between 0 and 25. it might be desirable to allow non-letter characters, but not count them. of course, you could explicitly test the value of the character to see if it is between 'a' and 'z'. however, an alternative is to go ahead and use the translated character as an index, and catch an if it occurs. since you want don't want to do anything when a non-letter occurs, the handler 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.2. now modify the body of the catch so that it prints a useful message (e. g., "not a letter") followed by the exception. compile and run the program. although it's useful to print the exception for debugging, when you're trying to smoothly handle a condition that you don't consider erroneous you often don't want to. in your print statement, replace the exception with the character that created the out of bounds index. run the program again; much nicer! // // countletters. java reads a words from the standard input and prints the number of// occurrences of each letter in that word.// import java. util. scanner; public class countletters{ public static void main(string[] args) { int[] counts = new int[26]; scanner scan = new scanner(system. in); //get word from user system. out. print("enter a single word (letters only, ): "); string word = scan. nextline(); //convert to all upper case word = word. touppercase(); //count frequency of each letter in string for (int i=0; i < word. length(); i++) counts[word. charat(i)-'a']++; //print frequencies system. out. println(); for (int i=0; i < counts. length; i++) if (counts [i] ! = 0) system. out. println((char)(i +'a') + ": " + counts[i]); }}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:00
Which parts of a presentation should be the most general? a. introduction and conclusion b. introduction and outline c. outline and conclusion d. outline and body
Answers: 1
question
Computers and Technology, 23.06.2019 08:30
All of these are true about using adhesive except: a. dissimilar materials can be joined. b. mixing tips are product and material specific. c. a specific application gun may be required. d. two-part adhesives are dispensed using two mixing tips
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
Given a link with a maximum transmission rate of 32.8 mbps. only two computers, x and y, wish to transmit starting at time t = 0 seconds. computer x sends filex (4 mib) and computer y sends filey (244 kib), both starting at time t = 0. statistical multiplexing is used, with details as follows packet payload size = 1000 bytes packet header size = 24 bytes (overhead) ignore processing and queueing delays assume partial packets (packets consisting of less than 1000 bytes of data) are padded so that they are the same size as full packets. assume continuous alternating-packet transmission. computer x gets the transmission medium first. at what time (t = ? ) would filey finish transmitting? give answer in milliseconds, without units, and round to one decimal places (e.g. for an answer of 0.013777 seconds you would enter "13.8" without the quotes)
Answers: 3
question
Computers and Technology, 23.06.2019 18:00
While inserting images, the picture command is usually used to insert photos from a digital camera, and the clip art command is usually used to a.edit the sizes and other characteristics of photos that have been inserted. b.take a screenshot of an image and copy it to the clipboard for pasting. c.search for drawings or other images from a library of prepared pictures. d.make illustrations using lines and shapes that are easy to manipulate.
Answers: 1
You know the right answer?
File countletters. java contains a program that reads a word from the user and prints the number of...
Questions
question
Mathematics, 26.11.2020 06:30
question
Mathematics, 26.11.2020 06:30
question
Physics, 26.11.2020 06:30
question
Mathematics, 26.11.2020 06:30
question
Mathematics, 26.11.2020 06:30
question
Mathematics, 26.11.2020 06:30
question
Mathematics, 26.11.2020 06:30
question
Mathematics, 26.11.2020 06:30
Questions on the website: 13722359