与私有变量相关的表达式的非法开头

Illegal start of expression relating to a Private variable

我正在尝试 运行 我的 AP 计算机科学老师提供给我们的一个项目来检查我们的工作。我一直在尝试两个 类 让老师的代码工作但无济于事。问题是当初始化私有变量 n 时,它给我一个错误读取 "illegal start of expression." 任何帮助将不胜感激。 这是代码:

 package eastersunday;

    public class Easter
{
public static void main(String[] args) 
{
   private int n;
   private int p;

   /**
      Constructs the date of Easter Sunday.
     * @param year
   */
   public Easter(int year)
   {
      int y = year;
      int a = y % 19;
      int b = y / 100;
      int c = y % 100;
      int d = b / 4;
      int e = b % 4;
      int g = (8 * b + 13) / 25;
      int h = (19 * a + b - d - g + 15) % 30;
      int j = c / 4;
      int k = c % 4;
      int m = (a + 11 * h) / 319;
      int r = (2 * e + 2 * j - k - h + m + 32) % 7;
      n = (h - m + r + 90) / 25;
      p = (h - m + r + n + 19) % 32;
   }

   /**
      Gets the month of Easter Sunday
      @return month of Easter Sunday
   */
   public int getEasterSundayMonth()
   {
      return n;
   }

   /**
      Gets the date of Easter Sunday
      @return date of Easter Sunday
   */
   public int getEasterSundayDay()
   {
      return p;
   }
}

试试这段代码,在 main 方法之外使用变量和函数

package eastersunday;

    public class Easter
{
public static void main(String[] args) 
{
}
   private int n;
   private int p;

   /**
      Constructs the date of Easter Sunday.
     * @param year
   */
   public Easter(int year)
   {
      int y = year;
      int a = y % 19;
      int b = y / 100;
      int c = y % 100;
      int d = b / 4;
      int e = b % 4;
      int g = (8 * b + 13) / 25;
      int h = (19 * a + b - d - g + 15) % 30;
      int j = c / 4;
      int k = c % 4;
      int m = (a + 11 * h) / 319;
      int r = (2 * e + 2 * j - k - h + m + 32) % 7;
      n = (h - m + r + 90) / 25;
      p = (h - m + r + n + 19) % 32;
   }

   /**
      Gets the month of Easter Sunday
      @return month of Easter Sunday
   */
   public int getEasterSundayMonth()
   {
      return n;
   }

   /**
      Gets the date of Easter Sunday
      @return date of Easter Sunday
   */
   public int getEasterSundayDay()
   {
      return p;
   }
}

我一眼就看出一个问题:你的代码中有一些悬空的括号。这使得你在 main 中声明了一些东西,你可能有意也可能没有,因为你没有用'}'关闭它。确保每个 { 都以 } 结尾,否则您的代码会给您一些错误。