错误:找不到符号;符号:变量keyBoard

时间:2012-02-12 02:25:33

标签: java

我有这个代码并试图编译它。但它给了我

  

错误:找不到符号

     

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));
  }
}

1 个答案:

答案 0 :(得分:1)

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

Scanner keyBoard = new Scanner(System.in);