String str=”hello java helloworld hello java hello java hahahaha”; 求出一个字符串中java出现次数

    xiaoxiao2022-06-26  81

    public static int getCount(String string,String terget){ int begin=0; int count=0; while((begin=string.indexOf(terget,begin))!=-1){ count++; begin+=terget.length(); } return count; } public static void main(String[] args) { String string="hello java helloworld hello java hello java hahahaha"; String terget="java"; int s=Test.getCount(string,terget); System.out.println(s); } }

     


    最新回复(0)