java跳出當前for循環執行下一次,java回車不終止_java 在console行輸入一串String后回車,仍無法停止。 下面的程序是計算相似度的,當用戶

 2023-12-25 阅读 27 评论 0

摘要:當用戶輸入關鍵字后,比如cowslove然后按回車,程序依然顯示在執行,無法停止,也沒有繼續下一步顯示出計算結果。如果把while(input.hasNext()){keywords.add(input.next().toLowerCa...當用戶輸入關鍵字后,比如 cows love 然后按回車,

當用戶輸入關鍵字后,比如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;

}

}

展開

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/194684.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息