【发布时间】:2021-10-01 00:45:03
【问题描述】:
我刚刚开始学习如何用 Java 编写代码。
任务
我在网上平台replit做了一个小程序。
程序比较两个ints:
- 它们是否相等
- 哪个大,哪个小
错误
我在编译时偶然发现了这些错误:
Main.java:22: error: cannot find symbol
System.out.println("El mayor es " + may);
^
symbol: variable may
location: class Main
Main.java:23: error: cannot find symbol
System.out.println("El menor es " + men);
^
symbol: variable men
location: class Main
2 errors
我的代码
class Main {
public static void main(String[] args) {
int a = 5;
int b = 6;
if (b==a)
{
System.out.println("Both digits are equivalent");
}
else
{
if (b>a)
{
int may = b;//may stands for the position of the greater number
int men = a;//men stands for the position of the smaller number
}
else
{
int may = a;
int men = b;
}
System.out.println("the bigger number is " + may);
System.out.println("the smaller number is " + men);
}
}
}
【问题讨论】:
-
我编辑了问题以使问题清晰且可重现。我可以阅读以下问题:“如何解决 Java 编译器错误...”。请按要求填写research for
[java] cannot find symbolon Stackoverflow,您会找到答案。因为这种编译器错误“找不到符号”对于 Java 新手来说很常见。 -
感谢编辑,我对这门语言还很陌生,所以我真的不知道如何命名它。
标签: java variables compiler-errors