subject
Engineering, 12.06.2020 05:57 Vampfox

The CountLetters application is limited to counting letters in a single word. Modify the CountLetters application to count the letters in an entire phrase, which contains spaces. Care must be taken to ignore the spaces and any other non alphabetic character found in the phrase. Be sure to change comments and variable names appropriately so that the reader of the application code understands that the letters in a phrase are counted. import java. util. Scanner;

public class CountLetters {

public static void main(String[] args) {
final int LOW = 'A'; //smallest possible value
final int HIGH = 'Z'; //highest possible value
int[] letterCounts = new int[HIGH - LOW + 1];
Scanner input = new Scanner(System. in);
String phrase;
char[] wordLetters;
int offset; //array index

/* prompt user for a phrase */
System. out. print("Enter a phrase: ");
phrase = input. nextLine();
input. close();

/* convert word to char array and count letter occurrences */
phrase = phrase. toUpperCase();
wordLetters = phrase. toCharArray();
for (int letter = 0; letter < wordLetters. length; letter++) {
offset = wordLetters[letter] - LOW;
letterCounts[offset] += 1;
}

/* show letter occurrences */
for (int i = LOW; i <= HIGH; i++) {
System. out. println((char)i + ": " + letterCounts[i - LOW]);
}
}

}

ansver
Answers: 3

Another question on Engineering

question
Engineering, 04.07.2019 18:10
Which from the following instrument is commonly used to detect the high pitch butzing sound in bearings? [clo4] a)-digital ultrasonic meter b)-infrared camera c)-spectroscopic d)-vibrometer
Answers: 2
question
Engineering, 04.07.2019 19:10
Plan an experiment to measure the surface tension of a liquid similar to water. if necessary, review the ncfmf video surface tension for ideas. which method would be most suitable for use in an undergraduate laboratory? what experimental precision could be expected?
Answers: 2
question
Engineering, 04.07.2019 19:10
The air in an automobile tire with a volume of 0.015 m3 is at 32°c and 140 kpa gage. determine the amount of air that must be added to raise the pressure to the recommended value of 206 kpa gage. assume the atmospheric pressure to be 128 kpa and the temperature and the volume to remain constant.[r-0.287 kj/kgk]
Answers: 3
question
Engineering, 05.07.2019 04:30
Technician a says that in a worm gear steering system, most excessive steering free play is usually found in the gearbox. technician b says that in a rack-and-pinion steering system, excessive free play can be found in the bushings. who is correct?
Answers: 2
You know the right answer?
The CountLetters application is limited to counting letters in a single word. Modify the CountLetter...
Questions
question
Mathematics, 05.12.2021 04:10
question
Mathematics, 05.12.2021 04:10
question
Mathematics, 05.12.2021 04:10
question
Mathematics, 05.12.2021 04:10
question
Mathematics, 05.12.2021 04:10
question
Mathematics, 05.12.2021 04:10
question
Mathematics, 05.12.2021 04:10
question
Chemistry, 05.12.2021 04:10
question
English, 05.12.2021 04:20