subject

The file count. java contains the skeleton of a program to read in a string (a sentence or phrase) and count the number of blank spaces in the string. the program currently has the declarations and initializations and prints the results. all it needs is a loop to go through the string character by character and count (update the countblank variable) the characters that are the blank space. since we know how many characters there are (the length of the string) we use a count controlled loop—for loops are especially well-suited for this.
1. add the for loop to the program. inside the for loop you need to access each individual character—the charat method of the string class lets you do that. the assignment statement
ch = phrase. charat(i);
assigns the variable ch (type char) the character that is in index i of the string phrase. in your for loop you can use an assignment similar to this (replace i with your loop control variable if you use something other than i). note: you could also directly use phrase. charat(i) in your if (without assigning it to a variable).
2. test your program on several phrases to make sure it is correct.
3. now modify the program so that it will count several different characters, not just blank spaces. to keep things relatively simple we'll count the a's, e's, s's, and t's (both upper and lower case) in the string. you need to declare and initialize four additional counting variables (e. g. counta and so on). your current if could be modified to cascade but another solution is to use a switch statement. replace the current if with a switch that accounts for the 9 cases we want to count (upper and lower case a, e, s, t, and blank spaces). the cases will be based on the value of the ch variable. the switch starts as follows—complete it.
switch (ch)
{
case 'a':
case 'a': counta++;
break;
case
}
note that this switch uses the "fall through" feature of switch statements. if ch is an 'a' the first case matches and the switch continues execution until it encounters the break hence the counta variable would be incremented.
4. add statements to print out all of the counts.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:30
What important technology has done the most to allow a businesses a chance to compete with larger international companies
Answers: 1
question
Computers and Technology, 23.06.2019 12:30
How is the brightness of oled of the diaplay is controled
Answers: 1
question
Computers and Technology, 24.06.2019 13:00
If you add the following to the query grid in an access query, what is it called? salestaxamt: [salestaxrate]*[totalsale] formula calculated field total calculation
Answers: 2
question
Computers and Technology, 24.06.2019 17:40
This assignment continues work on the online booking facility introduced at the end of chapter- 10. the work will be continued in the assignments for chapters 14 and 15 (a) assume that you will produce your online booking facility using an agile approach. i. suggest the kind of user research you would like to conduct for your product before iteration cycles begin. ii prioritize the requirements for your product according to business value, i.e which requirements are likely to provide the greatest business benefit, and sketch out the ux design work you would expect to undertake during the first four iteration cycles, i.e. cycle 0, and cycles 1 to 3. (b) using one of the mockup tools introduced above, generate a mockup of your product's landing page, as developed in the assignment for chapter-11 (c) using one of the patterns websites listed previously, identify suitable interaction patterns for elements of your product, and develop a software-based prototype that incorporates all the feedback and the results of the user experience mapping achieved at the end of chapter-11. if you do not have experience in using any of these, create a few html web pages to represent the basic structure of your website
Answers: 2
You know the right answer?
The file count. java contains the skeleton of a program to read in a string (a sentence or phrase) a...
Questions
question
Mathematics, 14.10.2019 10:10
question
Mathematics, 14.10.2019 10:10
question
Mathematics, 14.10.2019 10:10
question
Mathematics, 14.10.2019 10:10
Questions on the website: 13722359