如何解决 Java 编译器错误 "cannot find symbol"?

How to solve Java compiler-error "cannot find symbol"?

我刚开始学习如何在 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);
    }
  }
}

maymen 不在您最后两个打印语句的范围内。有不同的解决方案。其中之一是在 if 语句之外声明变量。 编辑以显示声明:我有一段时间没有写 java 但我相信声明是这样的:

...
else
{
  int may;
  int men;
  if (b>a)
  {
     may = b;
     men = a;
  }
  else
  {
     may = a;
     men = b;
  }
// print statements