Hello,
I've seen a ton of solutions for this but none seem to be working for me. I'm taking user input and making a charArray out of it. but the array is only as long as the length until the first whitespace is hit. So it the user types "help me" the array = h,e,l,p The code below is what I have without anything extra to get rid of the whitespace. I tried replaceAll (with many different regEx's) and still got "help" instead of "help me". also tried the charAt() method to try and buid a new string minus the spaces but was getting an error that I was trying to compare a char with a string. Please send some help this way.
thanks!
import java.util.*;
public class Vowels{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int numberVowels = 0;
String temp = "aeiou";
System.out.println("Please enter a phrase: ");
String phrase = scan.next();
char[] phraseList = phrase.toCharArray();
char[] vowels = temp.toCharArray();
for (int i = 0; i < phraseList.length; i++) {
char letter = phraseList;
for (int j = 0; j < vowels.length; j++) {
if (letter == vowels[j]) {
numberVowels++;
}
}
}
System.out.println(numberVowels);
}
}