Looping through an Array.
Hello, i need some help. I need to loop through an array to determine if there are vowels, consonants, a space etc. and then print for example. "character [x] located at position [x] is a consonant" or "character [x] located at position [x] is a vowel" etc. I have a small idea but cannot figure it out.
Code :
String ArrayMyName[] = {"Hector & Jorge % Farinas"};
int ArrayLenght = ArrayMyName.length;
for(int counter =0; counter < ArrayLenght; counter++)
{
String vowel = "a,e,i,o,u";
if(ArrayMyName[counter].equals(vowel))
System.out.println("Character" + ArrayMyName[counter] + "located in position " + ArrayMyName[counter] + "is a vowel.");
}
}
Thank you so much in advance..
Re: Looping through an Array.
Look at the methods of the String class such as indexOf(). The equals() method isn't the one to use here.
you need to have two loops: one to look at each name and within that loop, another loop to check the current name to see if it contains one of the letters you are interested in.
Re: Looping through an Array.
Where can I find the complete list of the String methods?
Re: Looping through an Array.
Is seems as though your loop compares each string in ArrayMyName to the entire string vowel. I would recommend comparing each character in the string to the character(s) you are going to want to find. Hope this helps.
Re: Looping through an Array.
The API doc address: Java Platform SE 6
Scroll down in the lower left for the String class.