万能百科  > 计算机   > 

[填空题] 请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。 [题目

2021-07-20   

[填空题] 请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。

[题目要求]

统计一个英文文本字符串包含的英文元音字母的个数,使程序的运行结果如下:

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表述元音的个数,因此统计出一个元音变量vowels就加1,所以此处应填vowels++。 [程序解析] 本程序统计一个字符串中元音字母的个数,然后输出。由于统计时是不区分大小写的,所以在比较前,先将字符串的每个字母都小写,再进行比较。

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

标签