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

前端 未结 9 2088
青春惊慌失措
青春惊慌失措 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:34

    This could/should be a one-liner

    System.out.println("the count of all vowels: " + (phrase.length() - phrase.replaceAll("a|e|i|o|u", "").length()));
    

    and its String only methods

提交回复
热议问题