java实现indexof方法(在java中求一个字符串在另一个字符串中多次出现的位置用indexOf方法怎么做)

本文目录
在java中求一个字符串在另一个字符串中多次出现的位置用indexOf方法怎么做
public class Practice
{
private static void readWord ( String input, String word, int offset, int count )
{
offset = input.indexOf (word, offset);
if (offset != -1)
{
System.out.println (word + " 在第 " + offset + " 个位置出现过.");
readWord (input, word, ++offset, ++count);
}
else
{
System.out.println (word + " 总共出现了:" + count + " 次.");
}
}
public static void main ( String args )
{
String input = "Look buddy, U got work hard and put yourself to the java, once U learned the heart of java, I can guarantee that U win.";
String word = "java";
readWord (input, word, 0, 0);
}
}
JAVA indexOf()
public class My {
public static void main(String args) {
String s = "xyzxyzxyzxyzxy";
String t = "xyzx";
int count=0;
while (! (s.indexOf(t) == -1))
{
s=s.replaceFirst(t,t.substring(t.length() - 1));
count++;
}
System.out.println(count);
}
}

本文相关文章:
更多文章:
form表单制作(为什么制作的form表单会在网页显示中多出一行)
2026年10月11日 09:10
teammate(teammate,company,partner)
2026年10月11日 06:10
javascript arraybuffer(javascript可以把base64编码转换成二进制代码吗求示例代码!)
2026年10月11日 04:00
text函数公式(excel中round和text函数的区别是什么)
2026年10月11日 03:50
google chrome打不开(chrome浏览器打不开怎么回事 浏览器打不开的处理方法)
2026年10月11日 02:00
websocket整合springboot(Springboot整合Websocket遇到的坑)
2026年10月11日 01:40
drawerlayout(android 怎样让drawerlayout设置的侧滑菜单的内容充满屏幕)
2026年10月10日 19:20
xor四位数怎么运算(单片机怎样用C语言实现4个数字间的异或)
2026年10月10日 17:50



