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:

Verified
The assignment to letter needs...View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Correct Answer:
Verified
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q17: Why does the Java statement System.out.println("answer =
Q18: How many constructors can a class have?<br>A)Exactly
Q19: All Java programs must define at least
Q20: Suppose s1 is a String variable.We want
Q21: Suppose temp is an array of 12
Q23: Suppose a try block needs to be
Q24: What is the value of sum after
Q25: A comment in Java that begins with
Q26: How is the finally keyword used in
Q27: Consider the following code that appears in