我有此代码,并尝试对其进行编译。但这给了我


错误:找不到符号

anotherEntry = keyBoard.nextInt();

符号:可变键盘

位置:类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));
  }
}

最佳答案

在尝试使用变量keyBoard之前,需要创建一个名为Scanner的变量并将其分配给新的keyBoard对象:

Scanner keyBoard = new Scanner(System.in);

10-07 13:18