[填空題] 請完善程序(程序文件名:Java_3.java)并進行調試。請在下畫線處填入正確內容,然后刪除下畫線。請勿刪除注釋行和其他已有的語句內容。 [題目
[填空題] 請完善程序(程序文件名:Java_3.java)并進行調試。請在下畫線處填入正確內容,然后刪除下畫線。請勿刪除注釋行和其他已有的語句內容。
[題目要求]
統(tǒng)計一個英文文本字符串包含的英文元音字母的個數,使程序的運行結果如下:
The text contained vowels:88
源程序:
public class Java_3
public static void main(String[] args)
String text = " Beijing, the Capital City, is the political, "
+ "cultural and diplomatic centre of China. It has"
+ "become a modern international cosmopolitan city"
+ " with more than 11 million people. The Capital"
+ " International Airport, 23.5 km from the city centre,"
+ "is China’s largest and most advanced airport. " ;
int vowels =0;
int (1) = text.length();
for(int i = 0;i<textLength; i++)
char ch=Character.toLowerCase( text. (2) );
if(ch==’a’||ch==’e’||ch==’i’||ch==’o’||ch==’u’)
正確答案:
vowels++
參考解析:由最后的輸出語句判斷出變量vowels表述元音的個數,因此統(tǒng)計出一個元音變量vowels就加1,所以此處應填vowels++。 [程序解析] 本程序統(tǒng)計一個字符串中元音字母的個數,然后輸出。由于統(tǒng)計時是不區(qū)分大小寫的,所以在比較前,先將字符串的每個字母都小寫,再進行比較。
詞條內容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學等領域),建議您咨詢相關領域專業(yè)人士。