标题:字符串数组源程序代码问题
只看楼主
daydayf
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-3-27
得分:0 
改一下:(1)
public class Q{
public static void main(String[] args){
String a[]=
{"The first snow came","how beautiful it was"}; //用{ }初始化
int count=0;
int and=0;
for(int
i=0;i<a.length;i++){ //初始化i=0
for(int j=0;j<a[i].length();j++){ //你实际上要比较的是数组里的每一个字符串元素
if(
a[i].charAt(j)=='t') //a[j].charAt(i)才是你需要比较的
count+=1;
else if (
a[i].charAt(j)=='T')
and+=1;
}
}
System.out.println("t出现的次数:"+count);
System.out.println("T出现的次数:"+and);
}
}

2006-04-03 09:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-54158-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.411104 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved