Solved

The Following Code Containing a Loop Attempts to Find How

Question 22

Essay

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;

Correct Answer:

verifed

Verified

The assignment to letter needs...

View Answer

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions