Remove all vowels in a string with Java

后端 未结 5 904
不思量自难忘°
不思量自难忘° 2021-01-19 12:46

I am doing a homework assignment for my Computer Science course. The task is to get a users input, remove all of the vowels, and then print the new statement.

I kno

5条回答
  •  失恋的感觉
    2021-01-19 13:13

    Character.isLetter('a')
    

    Character.isLetter(char) tells you if the value you give it is a letter, which isn't helpful in this case (you already know that "a" is a letter).

    You probably want to use the equality operator, ==, to see if your character is an "a", like:

    char c = ...
    if(c == 'a') {
        ...
    } else if (c == 'e') {
        ...
    }
    

    You can get all of the characters in a String in multiple ways:

    • As an array with String.toCharArray()
    • Getting each character from the String using String.charAt(index)

提交回复
热议问题