//该类捕抓键盘输入
import java.io.*;
public class ReadFromKeyboard{
public String text=null;
public String ReadMothod(){
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
try{
text= in.readLine();
}catch(IOException e){System.out.println(e);}
return text;
}
}
//Sch类作为查找词语被调用
class Sch{
Sch(){}
Sch(String str,char ch){
int count=0;
System.out.print("/""+ch+"/""+"出现的位置分别为:");
for(int i=0;i!=-1;){ //根据indesOf()方法,如果找到就返回第一次找到的位置,如果找不到就返回-1
int j=0;
j= str.indexOf(ch, i + j);
i=j;
if(i!=-1)
{
count++;
System.out.print(i+" ");
i++;
}
}
if(count>0)
System.out.println("/n"+ch+"共出现了"+count+"次");
else
System.out.println("没有在您输入的字符串中找到字符"+ch);
}
}
//主程序
public class ReadTest3 {
public static void main(String[] args) {
long t1=System.currentTimeMillis(),t2;
ReadTest2 s1=new ReadTest2();
String str=s1.ReadMothod();
// char str2=str.charAt(0);
// System.out.println(str2);
Sch s2=new Sch(str,'a');
t2=System.currentTimeMillis();
System.out.println("程序运行时间为:"+(t2-t1)/1000+"豪秒.");
}
}