简体   繁体   English

为什么我从下面的代码中收到错误 java.util.NoSuchElementException?

[英]Why am I getting the error java.util.NoSuchElementException from my code below?

I'm getting this error java.util.NoSuchElementException from my code below and I can't figure out why.我从下面的代码中收到此错误 java.util.NoSuchElementException ,我不知道为什么。 I'm attempting to write a code that reads an integer, a list of words, and a character.我正在尝试编写一个读取 integer、单词列表和字符的代码。 The integer signifies how many words are in the list. integer 表示列表中有多少个单词。 The output of the program is every word in the list that contains the character at least once.该程序的 output 是列表中包含该字符至少一次的每个单词。

       public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] arr = new String[n];
        for(int i = 0; i < n; ++i) {
            arr[i] = in.next();
        }
        char ch = in.next().charAt(0); //line that launches the error
        for(int i = 0; i < n; ++i) {
            if(arr[i].contains(""+ch)) {
                System.out.println(arr[i]);
            }
        }
    }

I have read this code and also run this code on my compiler.我已阅读此代码并在我的编译器上运行此代码。 I don't see any error in this code.我在这段代码中没有看到任何错误。 I think it is your compiler problem.我认为这是您的编译器问题。 I suggest you reinstall your compiler.我建议你重新安装你的编译器。 Here is your code and output:这是您的代码和 output:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会收到“ java.util.NoSuchElementException”? - Why am I getting a “java.util.NoSuchElementException”? 为什么我在在线编码 class 代码检查器上收到“线程中的异常”主“java.util.NoSuchElementException”错误? - Why am I getting a “Exception in thread ”main“ java.util.NoSuchElementException” error on a online coding class code checker? 不知道为什么我收到java.util.NoSuchElementException错误 - Not sure why i'm getting an java.util.NoSuchElementException error Java扫描程序:获取“java.util.NoSuchElementException”错误,不确定原因 - Java scanner: Getting “java.util.NoSuchElementException” error, not sure why 我在Java中遇到此运行时错误:java.util.NoSuchElementException,并且我不确定如何解决它 - I am getting this runtime error in java: java.util.NoSuchElementException, and I'm not sure how to fix it 在代码中获取 java.util.NoSuchElementException。 为什么? - Getting java.util.NoSuchElementException in the code. Why? 获取 java.util.NoSuchElementException - Getting java.util.NoSuchElementException java.util.NoSuchElementException错误? - java.util.NoSuchElementException Error? java.util.NoSuchElementException错误 - java.util.NoSuchElementException Error When writing Junit test case using mockito for findById() JPA method I am getting error as java.util.NoSuchElementException: No value present - When writing Junit test case using mockito for findById() JPA method I am getting error as java.util.NoSuchElementException: No value present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM