The following code containing a loop attempts to find how many times the letter ‘r’ appears in a string. But something is wrong with the loop. How would you fix it?
String s = “railroad”;
int count = 0;
char letter = s.charAt(index);
for (int index = 0; index < s.length(); ++index)
if (letter == ‘r’)
++count;
The assignment to letter needs to be moved down into the loop right before we check to see if the letter
is an r.
You might also like to view...
Most database tables have a(n) ____________, which is a column that can be used to identify a specific row.
a. identifier b. primary key c. key word d. column name
What is wrong with the following function template (Other than the fact that it really does almost nothing)?
```
template
When you click a text box border, _____.?
A. ?the sizing handles disappear B. ?the border disappears C. ?it changes to a dotted line D. ?it changes to a solid line
The Decrease Indent and Increase Indent buttons change the indents by ________ tab intervals
A) 1/4 inch B) 1/2 inch C) 1 inch D) 2 inch