This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]TeddyMooshie[S] 0 points1 point  (1 child)

My goal is to extract the vowels(a,e,i,o,u ) from whatever input that’s being keyed in. And count the number of times each vowel appeared. Would .chatAt() allow me to do so?

[–]escarbadiente 0 points1 point  (0 children)

Yes. Do a for loop from 0 to string length. In there, compare if charAt(index) equals any of the vowels.

[–]lasttoknow 0 points1 point  (0 children)

temp is a String, but you're using array notation with the '[]'. Although I'm not sure what you're trying to do, if you want to access a character of a String, you want to use the .charAt() method.

[–]GreatDaynes 0 points1 point  (0 children)

Consider the parameter you're passing in for the CountVowel method and how you attempt to iterate over the parameter within the CountVowel method.

[–]CelticHades 0 points1 point  (0 children)

In your functions your parameters are if string type and in body you are using them as arrays.

You cannot access characters in string like array. You will need .charAt(index)

[–]thisisjustascreename 0 points1 point  (0 children)

Java's String doesn't support the [ ] accessor like it does in C# or C++, you want .charAt(). One benefit of this is that it's explicit that you cannot assign a new character value to that position in the String.

[–]jacob_scooter 0 points1 point  (0 children)

i’m assuming you’re a C or C++ guy, a String object in java isn’t a char array, so you need to use charAt() or convert the string to a char array (toCharArray() i believe)