1要求就是 比如说 aa ss ss cc nmik ssd klkl ss dd 然后查出里面出现ss的次数 这个怎么做啊
不要是四的 要活的 就是你不管我输入什么 都可以 但是要判断里面的个数
不要是四的 要活的 就是你不管我输入什么 都可以 但是要判断里面的个数
解决方案 »
- 小弟问个SSH多表操作问题
- 关于FreeMarker问题---在线等
- 各位哥哥姐姐快开帮帮小弟吧,急死人了
- 郁闷找不到applicationContext.xml中的BEAN?
- Tomcat运行JSP文件时提示: The server encountered an internal error () that prevented it from fulfilling this request.
- 高效率地写10万行文本,您有何高招?!
- ★★☆【做过“进销存”的朋友来看看,来者有分,UP者有分,绝不食言】☆★
- java中获得手机验证与绑定怎么做
- struts简单问题
- 如何让自己的程序没有BUG!!!
- myeclipse 10中怎么开发flex
- orm里的集合属性初始化问题
然后就遍历比较就好了啊。
这句话不理解。。String str = "aa ss ss cc nmik ssd klkl ss dd ";
String strTemp = str.replaceAll("ss", "");
System.out.println((str.length()-strTemp.length())/"ss".length());
BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); // BufferedReader字符读取文件
String statement=input.readLine();
int l=0;
int count=1;
boolean t=false;
String tmp="";
for(int s=0;s<statement.length();s++){
String sub=statement.substring(s,s+1);
if(!sub.equals(" ")){
tmp+=sub;
}
}
l=tmp.length();
String c[]=new String[l];
for(int i=0;i<l;i++){
c[i]=tmp.substring(i,i+1);
}
for(int b=0;b<l;b++){
for(int e=0;e<b;e++){
if(c[b].equals(c[e])){
t=true;
}
}
if(t==false){
for(int d=b+1;d<l;d++){
if(c[b].equals(c[d])){
count++;
}
}
System.out.println(c[b]+"字符共出现了"+count+"次");
count=1;
}
t=false;
}
}
比如我写的这个 我想你们帮改哈 改成查询一个 不是单一的一个字母 我是查的不是单一的一个字母, 查询用空格隔开的 比如: aa aa bb ss 我想查的是aa出现的次数 而不是a出现的次数 就这个意思
*
*/
package com.test;/**
*
* Copyright: Copyright (c) 2010 Shenzhen Taiji Software Corparation
* abc.java
*
* @author 邹瑞金
* @version 1.0
* @date 2012-1-13 上午11:17:35
*/
public class abc { /**
* @param args
*/
public static void main(String[] args) {
String s = "aa ss ss cc nmik ssssd klkl ss dd";
String [] arrChars = s.split("ss");
System.out.println(arrChars.length-1); }}
package yym;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class www {
public static void main(String[] args) throws IOException {
System.out.print("请输入语句:");
BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); // BufferedReader字符读取文件
String statement=input.readLine();
int l=0;
int count=1;
boolean t=false;
String tmp="";
for(int s=0;s<statement.length();s++){
String sub=statement.substring(s,s+1);
if(!sub.equals(" ")){
tmp+=sub;
}
}
l=tmp.length();
String c[]=new String[l];
for(int i=0;i<l;i++){
c[i]=tmp.substring(i,i+1);
}
for(int b=0;b<l;b++){
for(int e=0;e<b;e++){
if(c[b].equals(c[e])){
t=true;
}
}
if(t==false){
for(int d=b+1;d<l;d++){
if(c[b].equals(c[d])){
count++;
}
}
System.out.println(c[b]+"字符共出现了"+count+"次");
count=1;
}
t=false;
}
}
}应该是这样的
String [] arrayContent = content.split("ss");
System.out.println(arrayContent.length-1);
*
* Copyright: Copyright (c) 2010 Shenzhen Taiji Software Corparation
* abc.java
*
* @author 邹瑞金
* @version 1.0
* @date 2012-1-13 上午11:17:35
*/
public class abc { /**
* @param args
*/
public static void main(String[] args) {
//String s = "aa ss ss cc nmik ssssd klkl ss dd";
Console console = System.console();
if (console != null) {
String s = new String(console.readLine("请输入你的字符:"));
s = " " + s +" ";
String [] arrChars = s.split("ss");
System.out.println(arrChars.length-1);
}else {
System.out.println("Console is unavailable.");
} }}
public static void main(String[] args) {
String s = "aa ss ss cc nmik ssd klkl ss dd";
System.out.println(findHit(s,"ss"));
}
public static int findHit(String str,String pattern) {
int hit = 0;
int pos = -1;
do {
pos = findStrPos(str, pattern, pos+1);
if(pos != -1)
++hit;
} while(pos != -1 && pos < str.length());
return hit;
}
public static int findStrPos(String str,String pattern,int fromindex) {
return str.indexOf(pattern, fromindex);
}
}