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
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q45: What is wrong with this Java statement?
Q46: Why does the Java statement System.out.println("answer =
Q47: Interpret the overall meaning of this if-statement:
if
Q48: Suppose c is a variable of type
Q49: How many times are the indicated statements
Q51: What is the value of sum after
Q52: Complete the following code so that it
Q53: Suppose s1 is a String variable.We want
Q54: Suppose temp is an array of 12
Q55: The following code attempts to find the
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents