當用戶輸入關鍵字后,比如cowslove然后按回車,程序依然顯示在執行,無法停止,也沒有繼續下一步顯示出計算結果。如果把while(input.hasNext()){keywords.add(input.next().toLowerCa...
當用戶輸入關鍵字后,比如 cows love 然后按回車,程序依然顯示在執行,無法停止,也沒有繼續下一步 顯示出計算結果。如果把 while(input.hasNext()){
keywords.add(input.next().toLowerCase());
java跳出當前for循環執行下一次,}去掉while loop后只執行里面的語句,則只會執行用戶輸入的第一個詞來計算。
public class Qurey {
public static void main(String[] args) throws FileNotFoundException{
System.out.println("please enter a file to read from: ");
java try catch finally執行順序、Scanner in = new Scanner(System.in);
String filename = in.next();
Set textkeywords = readWords(filename);
//in.close();
java輸入回車則結束輸入,System.out.println("please enter query keywords to seartch,1 to quit: ");
Set keywords = new HashSet();
Scanner input = new Scanner(System.in);
while(input.hasNext()){
console窗口出不來?keywords.add(input.next().toLowerCase());
}
int qIntersectD=0;
for(String word :keywords){
java終止循環語句。if(textkeywords.contains(word)){
qIntersectD++;
}
}
double Similarity=0;
Similarity=qIntersectD/(Math.sqrt(textkeywords.size())*Math.sqrt(keywords.size()) );
System.out.println("the similarity between query and document is : "+Similarity);
}
public static Set readWords(String filename) throws FileNotFoundException{
Set words = new HashSet();
Scanner in = new Scanner(new File(filename));
in.useDelimiter("[^a-zA-Z]+");
while(in.hasNext()){
words.add(in.next().toLowerCase());
}
in.close();
return words;
}
}
展開
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态