Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

toCharArray() with whitespace

807599Mar 10 2007 — edited Mar 10 2007
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);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2007
Added on Mar 10 2007
2 comments
542 views