Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在获取字数的同时显示单词搜索中的可能性_Java_Search_Word_Wordsearch - Fatal编程技术网

Java 在获取字数的同时显示单词搜索中的可能性

Java 在获取字数的同时显示单词搜索中的可能性,java,search,word,wordsearch,Java,Search,Word,Wordsearch,我这里有这个代码,它是单词搜索游戏的一部分。我试图让它在用户退出或时间结束时显示网格中出现的所有单词。到目前为止,我已经做到了这一点。我的问题是,我还想显示出现的单词数量,所以是一个数字。我怎样才能让它在顶部显示“有(单词数)当前单词”,然后是下面的单词 try { FileInputStream fstream = new FileInputStream("allWordsEn.txt");

我这里有这个代码,它是单词搜索游戏的一部分。我试图让它在用户退出或时间结束时显示网格中出现的所有单词。到目前为止,我已经做到了这一点。我的问题是,我还想显示出现的单词数量,所以是一个数字。我怎样才能让它在顶部显示“有(单词数)当前单词”,然后是下面的单词

try {
                            FileInputStream fstream = new FileInputStream("allWordsEn.txt");
                            DataInputStream in = new DataInputStream(fstream);
                            BufferedReader br = new BufferedReader(new InputStreamReader(in));
                            String strLine;
                            int presentWords = 0;
                            System.out.println("There were " + presentWords + " present words. They are:");
                            //Read File Line By Line
                            while ((strLine = br.readLine()) != null)   
                            {
                              if(canFind(strLine, t40)) 
                              {
                                presentWords++;
                                System.out.print(strLine + " ");
                              }
                            }
                            //Close the input stream
                            in.close();
使用a来建立您的单词列表,如下所示:

    //Before the loop
    StringBuilder s = new StringBuilder();
    //inside the loop
    s.append(strLine + " ");
    //after the loop
    System.out.println("There were " + presentWords + " present words. They are:" + s.toString());

请不要使用DataInputStream读取文本