我有一個程序,我正在處理的是計算字符串中元音的數量。我有它的工作,但如果Y後面跟着一個輔音,我不能把它算在Y.我的VOWEL_GROUP是「AEIOUaeiou」,它返回普通元音的數量,但不是'y'。我看它的charAt(i),看看它是否由除了元音組中的一個字符之外的其他東西所預置。 感謝您的幫助。 這裏是輸入和輸出,顯示錯誤在包含Y的字符串中計算元音,如果其後跟輔音
OUTPUT to console
Input
play. Why! Who!
There are 3 words in the file.
There are 2 vowels in the file.
There are Y 19 vowels in the file.
There are 3 sentences in the file.
// START of countThe Y Vowels********************************************
int YvowelCount=0;
for(int i=0;i<myFile.length();i++){
for(int j=0;j<VOWEL_GROUP.length();j++){
if(myFile.charAt(i)=='y' && myFile.charAt(i-1)!= VOWEL_GROUP.charAt(j)){
YvowelCount++;
}
}
}
// END of countThe Y Vowels**************************************************
你可以添加一些輸入輸出樣本? – Christian
我不明白'myFile.charAt(i)-1'這個部分,你確定這是你的期望嗎? – Christian