String and Char Help
- From: "BlackJackal" <mcdougal.robert@xxxxxxxxx>
- Date: 31 Jan 2007 13:44:23 -0800
I have a few questions but first here is my code.
public class CountVowels
{
public static void main(String[] args)
{
int vowel = 0;
int i;
char pos;
String String1 = "Event Handlers is dedicated to making your
event a most memorable one.";
int length = String1.length();
for(i = 0; i < length - 1 ; i++);
{
pos = String1.charAt(i);
if (pos == 'A' || pos == 'a' || pos == 'E' || pos == 'e' ||
pos == 'I' || pos == 'i' || pos == 'O' || pos == 'o' || pos == 'U' ||
pos == 'u') {
vowel += 1;
}
}
System.out.println("There are " + vowel + " vowels in this
String");
}
}
Question one is why does String1.length() return 70 when there are
only 69 chars. Second question is why does this code not count the
vowels in the String.
Thanks in advance
Robert
.
- Follow-Ups:
- Re: String and Char Help
- From: Alex Hunsley
- Re: String and Char Help
- From: Knute Johnson
- Re: String and Char Help
- Prev by Date: Re: blocking pattern
- Next by Date: Re: best obfuscator
- Previous by thread: Counting Char's Within Strings
- Next by thread: Re: String and Char Help
- Index(es):
Relevant Pages
|