?? checktext.java
字號:
package operation;
import entity.Dictionary;
import entity.Word;
//檢查文本類
public class CheckText {
private int errornumber; // 錯誤單詞數目
// 構造函數
public CheckText() {
errornumber = 0;
}
// 獲取錯誤單詞數目
public int getErrornumber() {
return errornumber;
}
// 判斷word是否在字典
// text 要檢查的單詞 dictionary字典
private boolean isInDictionary(Word word, Dictionary dictionary) {
String text = word.getWord(); // 保存word的單詞
int len = dictionary.getLength(text.charAt(0)); // 字典中首字母和單詞首字母相同的單詞個數
String s[] = dictionary.getWords(text.charAt(0)); // 獲取字典中首字母和單詞首字母相同的單詞
int i = 0;
for (i = 0; i < len; i++) {
if (text.toLowerCase().equalsIgnoreCase(s[i].toLowerCase())) { // 找到相同單詞返回true
return true;
}
}
return false;
}
// 返回不在字典中的單詞集合
// words 巖檢查的單詞集合 length 單詞長度 dictionary 字典
public Word[] errorWords(Word[] words, int length, Dictionary dictionary) {
int[] record = new int[length];
int i = 0;
errornumber = 0;
for (i = 0; i < length; i++) { // 逐個單詞檢查
if (!isInDictionary(words[i], dictionary)) { // 判斷是否在字典
record[errornumber] = i; // 記錄錯誤位置
errornumber++; // 錯誤數加1
}
}
Word error[] = new Word[errornumber];
for (i = 0; i < errornumber; i++) { // 記錄錯誤單詞
error[i] = words[record[i]];
}
return error;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -