Counting Char's Within Strings
- From: "BlackJackal" <mcdougal.robert@xxxxxxxxx>
- Date: 31 Jan 2007 13:27:13 -0800
Alright a couple of stupid questions here about strings and Chars.
First off 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");
}
}
First question is why does String1.length() return 70 when I only
count 69? The other question is why does this code always produce 0
vowels?
Thanks in advance I am just a little stumped.
.
- Follow-Ups:
- Re: Counting Char's Within Strings
- From: Alex Hunsley
- Re: Counting Char's Within Strings
- From: Knute Johnson
- Re: Counting Char's Within Strings
- Prev by Date: Re: Two more multithreading questions
- Next by Date: Re: blocking pattern
- Previous by thread: NTFS File System - File Owner
- Next by thread: Re: Counting Char's Within Strings
- Index(es):
Relevant Pages
|