为什么我这会抛出异常?
string index out
检查下你的变量i的取值范围是否超出字符串length
btw,when you ask questions pls show all the codes
int num = 0;
String string = "aabcdefgasshhrhaggggjdca";
for(int i = 0;i<string.length(); i++){
if(string.charAt(i)=='a'){
num++;
}
}
System.out.println(num);