java - 名称搜索程序问题。获取“解析时到达文件末尾}错误消息

标签 java compiler-errors

我似乎无法编译此代码,您能告诉我我做错了吗?
我尝试在所有位置添加},但似乎没有任何效果。非常感谢!
我可以使用哪些修复程序来使此代码正确编译?

import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;

public class NameSearch {
    public static void main(String args[]) throws IOException {

        ArrayList<String> searchName = new ArrayList <String>();
        String searchName = getNames();
        String boysNames;
        String girlsNames;

        displaySearchResults(searchName, boysNames, girlsNames);
    } 


    public static String getNames() {
        Scanner keyboard = new Scanner(System.in);

        File boysNames = new File("BoysNames.txt");
        Scanner inputFileBoysNames = new Scanner (boysNames);

        File girlsNames = new File("GirlsNames.txt");
        Scanner inputFileGirlsNames = new Scanner (girlsNames);

        System.out.println("Top 200 Name Search");
        System.out.print("Enter the name of your choosing here: ");

        String name = Keyboard.nextLine();
        Keyboard.close();
        return name;
    }

    public static void displaySearchResultsPing 
(String searchName, List<String> boysNames, List<String> girlsNames); 

    {

        System.out.println("\nBOOM! here are the results of your search: \n");

        boolean popularBoyName = boysNames.stream().anyMatch (p ->  p.equalsIgnoreCase(searchName));
        boolean popularGirlName = girlsNames.stream().anyMatch (p -> p.equalsIgnoreCase(searchName));


        if (popularBoyName) {
            System.out.println(searchName + "is a super popular boy's name. Pick another.");
        }
        if (popularGirlName) {
            System.out.println(searchName + "is a super popular girl's name. Pick another.");
        }
        if (!popularBoyName && !popularGirlName) {
            System.out.println (searchName + "is not a popular name. You have chosen correctly!");
        }
    }

最佳答案

一个问题是您的displaySearchResultsPing方法签名以;结尾。

另一个是在main方法中,您正在调用displaySearchResults(),但它不存在。

然后,您正在从文件中读取名称,然后丢弃这些变量。例如:

File boysNames = new File("BoysNames.txt");  // this is never kept or returned

而且boysNames方法中的girlsNamesmain变量从不设置为任何值-始终为null

关于java - 名称搜索程序问题。获取“解析时到达文件末尾}错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56120099/

相关文章:

Java统计包

java - Spring-Batch如何在不同的数据库中写入作业元数据?

c++ - C++即使包含路径中也不能包含opencv2/core.hpp。 ( window )

swift - Xcode Swift编译报错import name too long

c++ - 在#include 语句中使用垃圾字符没有编译器错误

java - 取 double[] HashMap 中每个索引的平均值并将其分配给输出 double[]

java - 如何在 webclient 中使用 retrieve 处理 500 错误代码

java - Mybatis 用于 select 语句的内联类型处理程序

c - '||' token 之前的预期表达式

c - 在 Solaris 上编译 ruby​​ 1.9.3 时出错