Developing Algorithms Using Strings

AP Computer Science A· difficulty 4/5

Count vowels in <code>String s</code>:

<code>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++; } </code></pre> For s = "education", count is

  • A

    3

  • B

    5

    check_circle
  • C

    6

  • D

    4

Explanation

e-d-u-c-a-t-i-o-n → e, u, a, i, o = 5 vowels.

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

Related questions