文件名称:Demo6
介绍说明--下载内容均来自于网络,请自行研究使用
编写一个方法,输出在一个字符串中,指定字符串出现的次数.方法原型为:
public static int countStr(String str1,string str2) -package defalt
public class Hellow {
public static void main(String args[])
{String str1="Hello,it is Tom speaking,who is that?"
String str2="is"
System.out.println(countStr(str1,str2))
}
public static int countStr(String str1,String str2){
int num=0
int indexFrom=0
indexFrom=str1.indexOf(str2,indexFrom)
while(indexFrom!=-1){
num++
indexFrom+=str2.length()
indexFrom=str1.indexOf(str2,indexFrom)
}
return num
}
}
public static int countStr(String str1,string str2) -package defalt
public class Hellow {
public static void main(String args[])
{String str1="Hello,it is Tom speaking,who is that?"
String str2="is"
System.out.println(countStr(str1,str2))
}
public static int countStr(String str1,String str2){
int num=0
int indexFrom=0
indexFrom=str1.indexOf(str2,indexFrom)
while(indexFrom!=-1){
num++
indexFrom+=str2.length()
indexFrom=str1.indexOf(str2,indexFrom)
}
return num
}
}
(系统自动生成,下载前可以参看下载内容)
下载文件列表
Demo6\.classpath
.....\.project
.....\.settings\org.eclipse.jdt.core.prefs
.....\bin\cn\ICompare.class
.....\...\..\NoStudentException.class
.....\...\..\Student.class
.....\...\..\Worker.class
.....\src\cn\ICompare.java
.....\...\..\NoStudentException.java
.....\...\..\Student.java
.....\...\..\Worker.java
.....\bin\cn
.....\src\cn
.....\.settings
.....\bin
.....\src
Demo6
.....\.project
.....\.settings\org.eclipse.jdt.core.prefs
.....\bin\cn\ICompare.class
.....\...\..\NoStudentException.class
.....\...\..\Student.class
.....\...\..\Worker.class
.....\src\cn\ICompare.java
.....\...\..\NoStudentException.java
.....\...\..\Student.java
.....\...\..\Worker.java
.....\bin\cn
.....\src\cn
.....\.settings
.....\bin
.....\src
Demo6