Question: I am trying to create a program that loops through a string, and if it is a vowel that adds it to a variable and then displays. The idea is not to use regular expressions so I use a for. And the problem is that it does not show me the result well, can you help me?

```
import java.util.Scanner;
import java.lang.StringBuilder;

public class ReemplazarVocales {
    public static void main(String[] args) {
        Scanner InputText = new Scanner(System.in);
        StringBuilder str = new StringBuilder();

        System.out.println("Escribe una frase\n");
        String Sentence = InputText.next();

        Sentence = Sentence.toLowerCase();
        char Vocal;

        for (int i=0;i <= Sentence.length();i++){

            Vocal = Sentence.charAt(i);
            String Consonant = Character.toString(Vocal);

            if (Consonant != "a" ||Consonant !="e" || Consonant !="i" || Consonant !="o" || Consonant!="u"){
                str.append(Consonant);
            }
        }

        System.out.println("\nTu frase sin vocales " + str);

    }
}

```

Answer: 
> 
> I am trying to create a program that loops through a string, and if it
> is a vowel that adds it to a variable and then displays.
> 
> 
> 

1. You are trying to get a character at the index = `Sentence.length()` which is not possible because java stores the characters in a string starting with index, `0` and therefore the last index is equal to the length-of-the-string minus one. Trying to access an index beyond the limits results in `StringIndexOutOfBoundsException`.
2. You do not need to convert a `char` into a `String` in order to add it to a `StringBuilder`; you can [append a `char` value directly to the `StringBuilder` object](https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#append(char)).
3. You need to use `==` instead of `!=`.
4. You need to use `Scanner#nextLine` instead of `Scanner#next` which stops scanning the input as soon as it encounters whitespace.

**A.** Replace

```
String Sentence = InputText.next();

```

with

```
String Sentence = InputText.nextLine();

```

**B.** Replace

```
for (int i=0;i <= Sentence.length();i++)

```

with

```
for (int i = 0; i < Sentence.length(); i++)

```

**C.** Replace

```
Vocal = Sentence.charAt(i);
String Consonant = Character.toString(Vocal);

if (Consonant != "a" ||Consonant !="e" || Consonant !="i" || Consonant !="o" || Consonant!="u"){
    str.append(Consonant);
}

```

with

```
Vocal = Sentence.charAt(i);
// String Consonant = Character.toString(Vocal);// It's not needed

if (Vocal == 'a' || Vocal == 'e' || Vocal == 'i' || Vocal == 'o' || Vocal == 'u') {
    str.append(Vocal);
}

```

I also recommend you follow the [Java naming conventions](https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html) e.g. `Vocal` should be `vocal` and `Sentence` should be `sentence` as per the naming conventions.
You wrote:

```
if (VocalP!="a" || VocalP!="e" || VocalP!="i" || VocalP!="o" || VocalP!="u")

```

which if you look closely will always be true.
for example if you take the first two options only:

```
if (VocalP!="a" || VocalP!="e")

```

if the letter is not 'a' OR the letter is not 'b'

and the letter is 'a' it will still evaluate to true because it is not 'e'
from your question you should be using == instead of !=
so try:

```
if (VocalP=="a" || VocalP=="e" || VocalP=="i" || VocalP=="o" || VocalP=="u")

```