//统计HelloWorld中L的个数
public class StringSub{
//1、肯定要创建一个方法test来解决问题呀
这里的参数input就是我要把HelloWorld放进方法去来统计它,world就是我要同统计那个字母
public static int test(String input,String world){
//2、因为我传入的字符串所以我需用创建数组str来接收字符串的长度
String[] str=new String[input.length()];
//3、因为我要统计world的个数所以我要创建count来计数
int count=0;
//4、通过for循环将input的字符串一个个放入数组中
for(int i=0;i<str.length;i++){
//5、将输入的input中的字符串从第i个到第i+1都放入数组str[]中
str[i]=input.substring(i,i+1);
//6、找到要统计的字母world在数组中的位置,找到要就开始统计
if(str[i].equals(world)){
count++;
}
}
}
return count;
}
//在main方法汇总测试
public static void main(String[] args){
System.out.println(test("helloworld","l"));
}