Remove all vowels in a string with Java

java, java.util.scanner

Solution

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)

Problem

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 know I could easily do it with this code: ``` string.replaceAll("[aeiou](?!\\b)", "") ``` But my instructor wants me to use nested if and else if statements to achieve the result. Right now I am using something like this: ``` if(Character.isLetter('a')){ 'do something' }else if(Character.isLetter('e')){ 'do something else' ``` But I am not sure what to do inside the `if` and `else if` statements. Should I delete the letter? Or is there a better way to do this? Seeing as this is my homework I don't want full answers just tips. Thanks!

Original source