So I am trying to make a program where I can enter any phrase, and the computer detects the vowels in the phrase, changing them to a #. Can someone help me out because I think I'm pretty sure I am doing it right, but it doesn't come out right? I already have included a Scanner.
System.out.println("Enter a phrase you like"); String phrase = input.nextLine(); int length = phrase.length(); for(int z = 0 ; z < length; z++) { //Starts the loop if(phrase.charAt(z) == 'a' || phrase.charAt(z) == 'A' || phrase.charAt(z) == 'e' || phrase.charAt(z) == 'E' || phrase.charAt(z) == 'i' || phrase.charAt(z) == 'I' || phrase.charAt(z) == 'o' || phrase.charAt(z) == 'O' || phrase.charAt(z) == 'u' || phrase.charAt(z) == 'U'){ System.out.print("#"); }//ends if statement 1 }//ends the Loop System.out.print(phrase);
So lets say I wrote: "John Doe is amazing"
It comes out as:
#######John Doe is amazing, meaning it knows the amount of vowels, but it wont replace them
Its supposed to be:
J#hn D## #s #m#z#ng