【问题标题】:why cant java find a symbol i have initialized? [duplicate]为什么java找不到我初始化的符号? [复制]
【发布时间】:2014-05-05 17:25:33
【问题描述】:

根据以下:

triangles.java:17: error: cannot find symbol
    shape = keyboard.nextChar();
                            ^
    symbol:   method nextChar()
    location: variable keyboard of type Scanner
1 error

为什么找不到符号?我已将键盘初始化为扫描仪。我该如何解决这个问题?

这是我初始化它的方式:

char shape;
shape = scanner.nextChar();

我已将 char 更改为 String,但什么也没做。我已经导入了扫描仪,所以这不是问题。

【问题讨论】:

  • 什么是nextChar()?为什么你会认为错误出现在shape,当错误消息说cannot find symbol,然后告诉你symbol: method nextChar()location是什么符号?
  • Scanner 没有 nextChar() 方法。
  • 您的编译错误显示为shape = keyboard.nextChar();,但您的代码sn-p 显示为shape = scanner.nextChar();
  • 相信你可以在这篇文章中找到答案:stackoverflow.com/questions/13942701/…

标签: java symbols


【解决方案1】:

如果您想在字符串变量中查找字符,只需执行以下操作:

 String str = scanner.nextLine(); // or scanner.next();
 char shape = str.charAt(i); // replace i with index of char you're trying to find.

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-14
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2013-02-21
    • 1970-01-01
    相关资源
    最近更新 更多