String s = "hello";
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'l') {
count++;
}
}
System.out.println(count);What is printed?
- A
1
- B
0
- Ccheck_circle
2
- D
3
Explanation
Iterating through "hello", the character 'l' appears at indices 2 and 3, so count = 2.