English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

it is a question for java students

2006-07-21 14:36:16 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

public int countVowels( String word ) {

int count = 0;

if( word != null ) {

for( int i = 0; i < word.length(); i++) {
if( "aeiouAEIOU".indexOf( word.charAt( i ) ) > 0 ) count++;
}

}

return count;
}

2006-07-24 07:15:54 · answer #1 · answered by BalRog 5 · 1 0

Count the no of vowels in a word? Let's assume you have the word stored in a variable called wrd. Counting is simple:
int len;
int count = 0;
char c;
len = wrd.length();
for(int i =0; i c = wrd.charAt(i);
if(c=='a' || c=='e' || c=='i' || c =='o' || c=='u')
count ++;
}

System.out.println("Number of vowels in " + wrd + " =" + count);

2006-07-21 21:45:55 · answer #2 · answered by SmartSpider 4 · 0 2

fedest.com, questions and answers