java - 名称搜索程序问题。在解析 } 错误消息时获取“到达文件末尾”
问题描述
我似乎无法编译这段代码,你能告诉我我做错了什么吗?我尝试在所有地方添加 },但似乎没有任何效果。太感谢了!我可以使用哪些修复程序来正确编译此代码?
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
和girlsNames
变量main
永远不会设置为任何值 - 总是null
。
推荐阅读
- python - 虽然不会与输入字符串中断
- docusignapi - Docusign - 沙盒 - 重定向 URI - 不起作用
- django - 更新来自外部 api 源的 django 模型的最佳方法?
- r - Azure HDInsight 群集中的 HDFS 路径
- javascript - 从另一个文件向命名空间/模块添加函数
- android - 如何在 ARCore 中的另一个门户场景中实现门户场景?
- c - 请问有人能解释一下这个递归代码吗?
- python - python中维基百科页面的内链和外链
- blur - 找不到 UIModalPresentationStyle 枚举值 blurOverFullScreen
- tags - Gitlab 项目标签和 Runner 标签;他们有关系吗?