贴出精简后代码
import java.util.Scanner;
import java.io.*;
public class c
{
public static void main(String []args)throws IOException
{
System.out.println("请输入要切割的句子");
Scanner scanner=new Scanner(System.in);
String s1=scanner.nextLine();
String s2="";
File sourceFile=new File("分词词表.txt");
BufferedReader buffer=new BufferedReader(new FileReader(sourceFile));
String temp=null;
int wLong=4;
int i=wLong;
String s3=s3=s1.substring(0,wLong);
boolean bo=false;
temp=buffer.readLine().trim();
System.out.println(temp);
while(!bo){
for(;temp!=null;)
{
if(s3==temp)
{
bo=true;
break;
}
else
{
temp=buffer.readLine().trim();
System.out.println(temp);
}
}
i=i-1;
s3=s1.substring(0,i);
}
s2=s2+s3+"/";
s1=s1.substring(i);
i=wLong;
System.out.println("切分后的句子:"+s2);
}
}
做了个分词词表的txt
if(s3==temp)
{
bo=true;
break;
}
当输入的s3与temp值一致时 循环没有退出 求助
------解决方案--------------------
- Java code
if(s3.equals(temp)){ bo=true; break;}