我写了一个可以查询一个文本里面的单词是否存在在字典里的程序,如果程序搜到了一个单词不在字典里就停止运行。可是老师给的这个文本明明每个都在字典里,可是我每次运行的时候就停在同个单词上。看了字典才知道,原来那个单词有两个意思,所以单词后面分别加了数字1和2,所以老是停在那个单词上。求怎么改这个程序,让他可以忽略单词后面的数字,然后只读单词呢?如果可以的话,能不能也加上一个可以限制要查询的文本,单词在1000个以内,如果超过就显示“超数”package escalera;import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
/**
*
* @author
*/public class comparapalabra {
public int count=0;
public comparapalabra(String nom) throws Exception{
FileReader fis1 = null;
BufferedReader bis1 = null;
FileReader fis2 = null;
BufferedReader bis2 = null;
String s1 = null;
String s2 = null;
Collection<String> c1 = new ArrayList<String>();
Collection<String> c2 = new ArrayList<String>();
Collection<String> cSame = new ArrayList<String>();
try{
fis1 = new FileReader("diccionaricatala.txt");
bis1 = new BufferedReader(fis1);
fis2 = new FileReader(nom);
bis2 = new BufferedReader(fis2);
while ((s1=bis1.readLine())!=null){
c1.add(s1);}
while ((s2=bis2.readLine())!=null){
c2.add(s2);
if(c1.contains(s2)){
cSame.add(s2);
System.out.println("单词"+(count+1)+"; "+s2);
count++;}else {
count++;
System.out.println("单词:"+count+";"+s2+" 错误;单词不在字典中。");
System.out.println("\n不是字梯,错误出现在单词"+count);
break;
}
}
}catch(IOException e){
}finally{
try{
fis1.close();
bis1.close();
fis2.close();
bis2.close();
}catch(IOException e){
}}}
}
import java.util.ArrayList;
import java.util.Collection;
/**
*
* @author
*/public class comparapalabra {
public int count=0;
public comparapalabra(String nom) throws Exception{
FileReader fis1 = null;
BufferedReader bis1 = null;
FileReader fis2 = null;
BufferedReader bis2 = null;
String s1 = null;
String s2 = null;
Collection<String> c1 = new ArrayList<String>();
Collection<String> c2 = new ArrayList<String>();
Collection<String> cSame = new ArrayList<String>();
try{
fis1 = new FileReader("diccionaricatala.txt");
bis1 = new BufferedReader(fis1);
fis2 = new FileReader(nom);
bis2 = new BufferedReader(fis2);
while ((s1=bis1.readLine())!=null){
c1.add(s1);}
while ((s2=bis2.readLine())!=null){
c2.add(s2);
if(c1.contains(s2)){
cSame.add(s2);
System.out.println("单词"+(count+1)+"; "+s2);
count++;}else {
count++;
System.out.println("单词:"+count+";"+s2+" 错误;单词不在字典中。");
System.out.println("\n不是字梯,错误出现在单词"+count);
break;
}
}
}catch(IOException e){
}finally{
try{
fis1.close();
bis1.close();
fis2.close();
bis2.close();
}catch(IOException e){
}}}
}
解决方案 »
- 连接池问题
- java新手问题 请大家帮帮忙
- 为什么一个show()会弹出2个窗口?
- String的问题,replaceAll是不是有问题啊,dx看看
- 各位大哥,除了JVM等要进行安装虚似机外,其它有没有支持JAVA在windows上独立运行的不需要进行安装的应用程序呢
- Application中,想让Frame监听所有按键事件,但是addKeyListener后不好使,各位大侠帮忙分析分析
- 谁有JBuilder的注册码,谢谢
- 构造方法可以是static的吗?为什么?
- 求救:哪位大侠有能把 .wav 变成 .au 的转换程序?
- 我该怎么做啦?
- 关于堆排序算法时间、空间复杂度问题
- 我的TCP编程怎么在eclipse里无法进行相互发送信息 高手帮改下 急!!!!
可以解释一下 这个传入参数的 具体含义吗?