对于作业,我必须编写以下代码:
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 个错误,显示“无法解析符号,符号:类 Scanner,位置:类 Words,Scanner userInput=new Scanner(System.in)”。我不确定错误在哪里。我应该使用 BufferedReader 代替输入吗?