| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice Test
Share
easy Solved by 5 students
String Iteration Character Count
< Prev
Next >

What is the value of the variable result after the following code segment is executed?

String word = "COMPUTER";
int result = 0;
for (int i = 0; i < word.length(); i++) {
    if (word.substring(i, i + 1).equals("E") || 
        word.substring(i, i + 1).equals("U")) {
        result++;
    }
}
A

3

B

0

C

2

D

1

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1sgarv251311 0m 00s 100
#2hitrishabhatia12 0m 00s 90
#3y.seong202712 1m 50s -20
#4suhanakochhar00611 2m 58s -78
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy