首页 文章

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

提问于
浏览
0

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

错误:找不到符号anotherEntry = keyBoard.nextInt(); symbol:变量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 回答

  • 1

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

    Scanner keyBoard = new Scanner(System.in);
    

相关问题