2个回答
展开全部
package test;
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);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package com;
import java.io.*;
public class Test
{
public static void main(String[] args) throws Exception
{
String str = "abcaaabckljldabcljljf";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入要查找的单词");
String findStr = br.readLine();
int strIndex = 0;
int sum = 0;
if (findStr != null && findStr.length() != 0)
{
strIndex = str.indexOf(findStr);
if (strIndex == -1)
{
System.out.println("没找到");
}
else
{
System.out.print("位置:");
while (strIndex != -1)
{
System.out.print(strIndex + " ");
//从之前找的位置的后面接着找
strIndex = str.indexOf(findStr, strIndex + 1);
sum++;
}
System.out.println("\r\n总共:" + sum + "个");
}
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询