String Iteration Character Count
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
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #2 | hitrishabhatia | 1 | 2 | 0m 00s | 90 |
| #3 | y.seong2027 | 1 | 2 | 1m 50s | -20 |
| #4 | suhanakochhar006 | 1 | 1 | 2m 58s | -78 |
APFIVE