主题:[讨论]哪个高手帮我看看这程序,急...............
import java.io.*;
public class Text
{
public static void main(String [] agrs)
{
int count=0;
int first=0;
int second=0;
String text="welcome to you welcome to you welcome to you welcome to you";
String s="";
String subText=text;
System.out.println("请输入要统计的词;");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
}catch(IOException e){}
for(int i=1;i<=text.length();i+=second+1)
{
second=subText.indexOf("");
String temp=subText.substring(first,second);
if(s.equalsIgnoreCase(temp)) count++;
subText=subText.substring(second+1);
}
if(count==0)
System.out.println("词"+s+"没有出现");
else
System.out.println("词"+s+"出现"+count+"次");
}
}
为什么我输入to结果说没出现过?
public class Text
{
public static void main(String [] agrs)
{
int count=0;
int first=0;
int second=0;
String text="welcome to you welcome to you welcome to you welcome to you";
String s="";
String subText=text;
System.out.println("请输入要统计的词;");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=in.readLine();
}catch(IOException e){}
for(int i=1;i<=text.length();i+=second+1)
{
second=subText.indexOf("");
String temp=subText.substring(first,second);
if(s.equalsIgnoreCase(temp)) count++;
subText=subText.substring(second+1);
}
if(count==0)
System.out.println("词"+s+"没有出现");
else
System.out.println("词"+s+"出现"+count+"次");
}
}
为什么我输入to结果说没出现过?