日期:2014-05-20 浏览次数:20741 次
public class CeShi{
public static void main(String[] args){
String a = "java";
int count = 0;
int index = -1;
String str = "sunjavahpjavaokjavajavaandjavahahajavagoodjava";
/*String str = "sunjavahpjavaokjavajavahahajavagoodjava";
在字符串中多加了一个javaand就报异常,如果不加and就不会报错*/
System.out.println(str.indexOf(a));
while((index = str.indexOf(a))!= -1){
str = str.substring(index+str.indexOf(a));
count++;
}
System.out.println(count);
}
}
package csdn.programbbs_627;
public class CeShi{
public static void main(String[] args){
String a = "java";
int count = 0;
int index = -1;
String str = "sunjavahpjavaokjavajavaandjavahahajavagoodjava";
/*String str = "sunjavahpjavaokjavajavahahajavagoodjava";
在字符串中多加了一个javaand就报异常,如果不加and就不会报错*/
System.out.println(str.indexOf(a));
while((index = str.indexOf(a))!= -1){
str = str.substring(a.length() + str.indexOf(a));
count++;
System.out.print(index + " ");
}
System.out.println();
System.out.println("The count: " + count);
}
}