gpt4 book ai didi

java - 错误: cannot find symbol; symbol: variable keyBoard

转载 作者:行者123 更新时间:2023-12-01 15:33:35 26 4
gpt4 key购买 nike

我有这段代码并尝试编译它。但它给了我

error: cannot find symbol

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

最佳答案

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

Scanner keyBoard = new Scanner(System.in);

关于java - 错误: cannot find symbol; symbol: variable keyBoard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9245913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com