package com.heima.test;
import java.io.*;
public class wordtext {
public static void main(String[] args) {
String s = " ";
String w = " ";
System.out.print("input:\n");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
s = in.readLine();
System.out.println(s);
} catch (IOException e) {
}
System.out.print("input text word!");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
w = in.readLine();
System.out.println(w);
} catch (IOException e) {
}
int wLen = w.length();
int sLen = s.length();
int beginIndex = 0;
int endIndex = wLen;
int count = 0;
//sLen - wLen就是走过的距离
for(int i = 0; i < sLen - wLen; i++){
String word = s.substring(beginIndex, endIndex);
if(word.equalsIgnoreCase(w)){
count++;
}
beginIndex++;
endIndex++;
}
if (count == 0)
System.out.println("there no " + w);
else
System.out.println("there" + count + w);
// int first = 0, second = 0, end = 0;
// for (int i = 1; i <= s.length(); i += second + 1) {
// second = s.indexOf(" ");
// String t = s.substring(first, second);
// s = s.substring(second + 1);
// if (w.equalsIgnoreCase(t))
// end++;
// }
// if (end == 0)
// System.out.println("there no " + w);
// else
// System.out.println("there" + end + w);
}
}
是别人提出问题代码后,我修改后得出的,有不足,不是自己的就没去改了
分享到:
相关推荐
select f_find('Ap@2233ll@@l@@','@') from dual 返回结果为5,代表‘@’在该字符串中出现5次。 同理 select f_find('Ap@223SWEQQQ3ll@@l@@','Q') from dual---返回3,代表Q在字符串中出现了3次, select f_find('我...
vfp统计字符串中某字符重复出现次数,可以扩展到统计vfp数据库表中某字段中某字符重复出现的次数。
找出一个字符串中出现次数最多的子字符串,并返回重复次数。使用java编写
得出一个字符串中的连续出现次数最多的子串
String对象的方法 方法一: indexOf() (推荐) var str = "123" console.log(str.indexOf("2") !...match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。 方法三: search()
从字符串中查找字符出现次数的方法和性能对比
笔试题 还是那个查找一个字符串中出现次数最多的字符 java 代码2
C语言编程-编写一个函数,该函数可以统计一个长度为2的字符串在另一个字符串中出现的次数;
任意输入一个字符串,判断输出字符串中出现次数最多的字母。
判断一个字符串是不是出现在另一个字符串中,解题思路很清晰简单适合初学者
输入字符串,输出字符串中出现次数最多的字母及其出现次数。如果有多个字母出现次数一样,则按字符从小到大顺序输出字母及其出现次数。
输入一个字符串,该字符串中可以包含&^$^#@*任何符号以及空格。输入以回车结束。 • Output 有多行。输出该字符串中每个出现过的数字,然后在冒号“:”后面输出该数字出现的次数。按数字大小,从小到大的顺序输出。...
一个统计字符串中每个字符出现次数并排序的工具,统计一段字符中出现次数最多的字。
获取字符在字符串中出现的次数VC实现 共享
自己编的java判断一个字符串是否对称的,忘指导。判断一个字符串是否是对称字符串(方法改进) (一个一个比较) 例如"abc"不是对称字符串,"aba"、"abba"、"aaa"、"mnanm"是对称字符串
根据所给定的条件,从父字符串中查询出子字符串出现的次数,并返回。
删除一个字符串中出现次数最少的字符,样例输入:abcdd,样例输出:dd
c++使用vector统计字符串中单词出现的次数的方式,可以预先设置单词和句子,并给出句子中单词出现的次数
ES6--javascript判断一个字符串是否存在另一个字符串中
查找字符串 输入两个字符串,自动搜寻字符串出现次数和出现的位置