阅读下列Java代码,运行后正确的输出结果是( )。
public class Test {
public int coutStr(String[]arry,String str){
int count=0;
for(int i=0;i<arry.length;i++){
if(arry[i].indexOf(str)!=-1)
count++;
}
return count;
}
public static void main(String[] args) {
String[]arry={"happy","apple","money","ending"};
String findStr="a";
Test test=new Test();
int count=test.coutStr(arry,findStr);
System.out.println("此Java的数组中有"+count+"个字符串包含字符"+findStr);
}
}
A.此Java的数组中有1个字符串包含字符a
B.此Java的数组中有2个字符串包含字符a
C.编译错误
D.正常编译,运行时报错