package dict;
import java.io.*;
import java.util.Scanner;
public class Dict1 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in); //定义用户输入
System.out.println("###################################");
System.out.println("###################################");
System.out.println("#########欢迎进入英文字典程序#########");
System.out.println("###################################");
System.out.println("###################################");
while(true){
System.out.print("请输入你要翻译的英文单词(回车退出):");
String input = sc.nextLine(); //nextLine()吸取字符前后的空格/Tab键,回车键截止
if(input.equals("")){ //判断输入是否为空,回车即退出程序
break;
}else{
InputStream is = Dict1.class.getResourceAsStream("words.txt"); //获取文件路径
Scanner isSc = new Scanner(is); //转化为文件流
while (isSc.hasNext()) { //死循环
String line = isSc.nextLine(); //用于临时存储读取到文件中的数据
if(isSc.hasNext()){
if (line.split("t")[0].equals(input)) { //用t分隔读取的字符串,判断字符串数组中第一个元素是否和输入的字符串相等
System.out.println(line); //输出查到的结果
break; //跳出循环
}
}
else{
System.out.println("非常遗憾,没有找到你要翻译的单词 "+input);
}
}
}
}
}
}