2015-07-12 32 views
-1

我已經寫了下面的代碼段:意外的錯誤(全局變量/枚舉)

import java.util.Scanner; 

public class Congress { 
    public static int age; 
    public static int ctzn; 
    public static boolean eligibleForSenate() { 
     if (age >= 25 && ctzn >= 7) { 
     return true; 
     } else { 
     return false; 
     } 
    } 
    public static boolean eligibleForHouse() { 
    if (age >= 30 && ctzn >= 9) { 
     return true; 
    } else { 
     return false; 
    } 
    public static void main(String[] args) { 
    System.out.print("Enter age of candidate: "); 
    Scanner sc = new Scanner(System.in); 
    age = sc.nextInt(); 
    System.out.println(); 
    System.out.print("Enter years of U.S. Citizenship: "); 
    ctzn = sc.nextInt(); 
} 
} 
} 

這使我在主線錯誤。我相信這與全球變數有關。我該如何解決它?

+1

錯字:在'main'之前移動最後一個大括號... – Reimeus

+0

您忘了指定是什麼錯誤。 –

回答

2

有一個錯字:: 更改代碼如下::

import java.util.Scanner; 

    public class Congress { 
     public static int age; 
     public static int ctzn; 
     public static boolean eligibleForSenate() { 
      if (age >= 25 && ctzn >= 7) { 
      return true; 
      } else { 
      return false; 
      } 
     } 
     public static boolean eligibleForHouse() { 
     if (age >= 30 && ctzn >= 9) { 
      return true; 
     } else { 
      return false; 
     } 
     } 
     public static void main(String[] args) { 
     System.out.print("Enter age of candidate: "); 
     Scanner sc = new Scanner(System.in); 
     age = sc.nextInt(); 
     System.out.println(); 
     System.out.print("Enter years of U.S. Citizenship: "); 
     ctzn = sc.nextInt(); 
    } 

    } 
+0

感謝您的幫助:) –

2

你的括號不匹配,添加一個右括號}main前,從中刪除的最後一行。

+0

非常感謝:) –