简体   繁体   English

错误:找不到符号; 符号:可变键盘

[英]error: cannot find symbol; symbol: variable keyBoard

I have this code and tried to compile it. 我有此代码,并尝试对其进行编译。 But it gave me 但这给了我

error: cannot find symbol 错误:找不到符号

anotherEntry = keyBoard.nextInt(); anotherEntry = keyBoard.nextInt();

symbol: variable keyBoard 符号:可变键盘

location: class DemoVariables3 位置:类DemoVariables3

Any clue why? 有什么线索吗?

Code: 码:

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之前,需要创建一个名为keyBoard的变量并将keyBoard分配给新的Scanner对象:

Scanner keyBoard = new Scanner(System.in);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM