Java 扫描仪输入错误
对于作业,我必须编写以下代码:Java 扫描仪输入错误,java,Java,对于作业,我必须编写以下代码: import java.util.Scanner; public class Words { public static void main(String[] args) { //Display welcome message System.out.println("Welcome to the String Function Event!"); Scanner userInput = new Scann
import java.util.Scanner;
public class Words {
public static void main(String[] args) {
//Display welcome message
System.out.println("Welcome to the String Function Event!");
Scanner userInput = new Scanner(System.in);
String result1;
System.out.print("Please input the first word:");
result1=userInput.next();
String result2;
System.out.print("Please input the second word:");
result2=userInput.next();
System.out.println("The words you chose are " +result1+ " and " +result2+ ".");
}
}
当我尝试编译它时,它在命令提示中给了我3个错误,即“无法解析符号,符号:类扫描程序,位置:类单词,扫描程序用户输入=新扫描程序(System.in)”。我不确定错误在哪里。
我应该使用BufferedReader作为输入吗 您的代码非常好。您需要确保安装了最新版本的JDK。要做到这一点,请从这里获取最新的SDK:您的代码绝对不错。您需要确保安装了最新版本的JDK。为此,请从此处获取最新的SDK:如果继续出现此错误,可以跳过使用Scanner 你可以试试
using java.io.Console;
public class Words{
public static void main(String[] args){
Console con = new System.Console();
System.out.println("Enter some text");
String input = con.readLine();
}
}
这里有一个例子
Java文档如果继续出现此错误,可以跳过使用Scanner 你可以试试
using java.io.Console;
public class Words{
public static void main(String[] args){
Console con = new System.Console();
System.out.println("Enter some text");
String input = con.readLine();
}
}
这里有一个例子
Java文档中的代码是绝对正确的。请安装最新版本的JDK并重试。您的代码绝对正确。请安装最新版本的JDK并重试。您的代码很棒,只是有一个小错误。您只需在userInput.next之后输入行,它就会正常工作。它以粗体字更正
String result1;
System.out.print("Please input the first word:");
result1 = userInput.next**Line**();
String result2;
System.out.print("Please input the second word:");
result2 = userInput.next**Line**();
你的代码很棒,只是有一个小错误。您只需在userInput.next之后输入行,它就会正常工作。它以粗体字更正
String result1;
System.out.print("Please input the first word:");
result1 = userInput.next**Line**();
String result2;
System.out.print("Please input the second word:");
result2 = userInput.next**Line**();
您使用的是哪个版本的JDK?Scanner是在1.5版本中引入的(目前已经很老了),看起来不错me@SJuan76哦我刚检查过我的。它是1.4.6,这就是原因。我将获得最新版本并试用。非常感谢。我不知道!请检查文件夹中是否有any Scanner类您使用的是哪个版本的JDK?Scanner是在1.5版本中引入的(目前已经很老了),看起来不错me@SJuan76哦我刚检查过我的。它是1.4.6,这就是原因。我将获得最新版本并试用。非常感谢。我不知道!请检查文件夹中是否有any Scanner类。我下载了它,并检查是否安装了正确的版本,但在再次尝试编译后,它仍然无法工作!再次检查你的版本,我是肯定的。上面写着“java版本1.7.0_25”。我在用记事本。我必须将它保存在java文件箱中吗?现在我正在将它保存在我以前下载的bin中。我下载了它并检查是否安装了正确的版本,但是在再次尝试编译它之后,它仍然无法工作!再次检查你的版本,我是肯定的。上面写着“java版本1.7.0_25”。我在用记事本。我必须将它保存在java文件箱中吗?现在我把它保存在我以前下载的垃圾箱里。