Developing Algorithms Using Strings

AP Computer Science A· difficulty 4/5

String s = "education";
int count = 0;
for (int i = 0; i < s.length(); i++) {
  char c = s.charAt(i);
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    count++;
  }
}
System.out.println(count);

What is printed?

  • A

    5

    check_circle
  • B

    3

  • C

    4

  • D

    9

Explanation

"education" contains the vowels e, u, a, i, o — that's 5 vowels.

Want 10 more like this — adaptive to your weak spots?

Related questions