Java NoTouchElementException:未找到行。?
一般来说,我对Java和计算机科学都是新手,我经常从以下代码中得到相同的错误:Java NoTouchElementException:未找到行。?,java,java.util.scanner,Java,Java.util.scanner,一般来说,我对Java和计算机科学都是新手,我经常从以下代码中得到相同的错误: Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at Trivedi_Chatbot.main(Trivedi_Chatbot.java:28) 如果可以的话,请
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.base/java.util.Scanner.nextLine(Scanner.java:1651)
at Trivedi_Chatbot.main(Trivedi_Chatbot.java:28)
如果可以的话,请帮助我
import java.util.Scanner;
import java.util.Date;
public class Trivedi_Chatbot
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Hi there! My name is Alexa Jr!");
String input = scan.nextLine();
while(!input.equalsIgnoreCase("Goodbye"))
{
if ((input.equalsIgnoreCase("What's up?")) || (input.equalsIgnoreCase("Whats up")))
{
System.out.println ("Roof or sky, depending on if you're in a building.");
}
else if (input.equalsIgnoreCase("What's the date?")){
Date d = new Date();
System.out.println("Today's date is " + d);
}
input = scan.nextLine();
}
System.out.println("Goodbye! See you soon!");
}
}
您需要在cmd或ide(如eclipse或netbeans)中运行应用程序
cmd上的示例:
这是您的程序在终端上运行的记录:
$ ls
Trivedi_Chatbot.class
$ java Trivedi_Chatbot
Hi there! My name is Alexa Jr!
whats up
Roof or sky, depending on if you're in a building.
goodbye
Goodbye! See you soon!
$ java Trivedi_Chatbot </dev/null
Hi there! My name is Alexa Jr!
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.base/java.util.Scanner.nextLine(Scanner.java:1651)
at Trivedi_Chatbot.main(Trivedi_Chatbot.java:13)
$ls
Trivedi_Chatbot.class
$java Trivedi_Chatbot
你好!我的名字叫小Alexa!
怎么了
屋顶或天空,取决于您是否在建筑物中。
再见
再见!期待很快与您见面!
$java Trivedi_Chatbot适用于我,你如何运行你的程序?你如何运行我的程序?我正在使用一个基于chrome浏览器的名为Sololearn的编译器。