Use string methods to find and count vowels in a string?

前端 未结 9 2096
青春惊慌失措
青春惊慌失措 2020-12-02 02:04

I have this problem for homework (I\'m being honest, not trying to hide it at least) And I\'m having problems figuring out how to do it.

Given the following declarat

9条回答
  •  不思量自难忘°
    2020-12-02 02:30

    The i++ increments i after is has been used, so you're essentially saying string.substring(i,i). Since the ending mark is exclusive, this will always return an empty string. An easy fix would be to just change it to

    j = phrase.substring(i, ++i);
    

    Hope that helps!

提交回复
热议问题