-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFind.java
More file actions
66 lines (62 loc) · 1.93 KB
/
Copy pathFind.java
File metadata and controls
66 lines (62 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
编写一个“英汉-汉英”字典。输入英文,输出中文解释;输入中文,输出相关的英语单词。
*/
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
class txttest {
public static String [] toArrayByRandomAccessFile(File file) {
InputStreamReader isr;
String str;
String []ww = new String [7987];
try {
isr = new InputStreamReader(new FileInputStream(file), "utf-8");
BufferedReader fileR = new BufferedReader(new FileReader(file));
int i=0;
while ((str = fileR.readLine())!= null) {
ww[i++]=str;
}
fileR.close();
} catch (IOException e) {
e.printStackTrace();
}
return ww;
}
}
class compare {
public static int com(String g, String j) {
String[] ce = j.split(" ");
int flag=0;
if (g.compareTo(ce[0]) == 0) {
System.out.println(ce[1]);
System.out.println();
flag=1;
}
if(ce[1].contains(g)==true){
System.out.println(ce[0]);
System.out.println();
flag=1;
}
return flag;
}
}
public class Find {
public static void main(String args[]) {
File file = new File("src/dictionary.txt");
String st[] = txttest.toArrayByRandomAccessFile(file);
Scanner input = new Scanner(System.in);
while(true){
System.out.println("input one word(press 0 to exit):");
String t = input.next();
if(t.compareTo("0")==0)break;
int flag=0;
for(int i=0;i<7987;i++){
flag=compare.com(t,st[i]);
if(flag==1)break;
}
if(flag==0)
System.out.println("without this word!");
System.out.println();
}
}
}