First, recognize that vowels.substring(0)
doesn't do anything. A substring from position 0
is equivalent to the string itself.
The string vowels
, or "aeiou"
, doesn't appear anywhere in "mathematics"
, so indexOf
will return -1
11 times ("mathematics"
is length 11
). Therefore, the result of number
at the end is -11
.
While it's not clear exactly what you want, if you want to get the positions of each of the vowels in the string s
, you'll have to re-write your for
loop and use charAt(i)
or substring(i, i + 1)
.