我有这个代码并试图编译它。但它给了我
错误:找不到符号
anotherEntry = keyBoard.nextInt();
symbol:variable keyBoard
location:class DemoVariables3
有什么线索?
代码:
import java.util.Scanner;
public class DemoVariables3
{
public static void main(String[] args)
{
int entry;
int anotherEntry;
System.out.print("Enter another integer ");
anotherEntry = keyBoard.nextInt();
System.out.print("The other entry is ");
System.out.println(anotherEntry);
System.out.println(entry + "plus" +
anotherEntry + "is" + (entry + anotherEntry));
}
}
答案 0 :(得分:1)
在尝试使用变量keyBoard
之前,您需要创建一个名为Scanner
的变量并将其分配给新的keyBoard
对象:
Scanner keyBoard = new Scanner(System.in);