求大神解答
public class Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] str={"abcdaabesase"};
int count=0;
for(int i=0;i<str.length;i++){
if(str[i]=="a"){
count++;
}
}
System.out.println("a字母出現(xiàn)"+count+"次"); //結(jié)果什么是0次啊
}
}
2015-08-05
因為你數(shù)組定義的時候只有一個下標,長度只是1,值是abcdaabesase。
建議把這一行
改成
全代碼
2015-08-05
String[] str={"abcdaabesase"};你這樣表示是一個字符串,你可以打印一下System.out.println(str.length);只會顯示1,所以你的字符串是abcdaabesase,并沒有a