| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 896 人关注过本帖
标题:字符串数组源程序代码问题
只看楼主 加入收藏
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
快速回复:字符串数组源程序代码问题
数据加载中...
 
   



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

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