我已經寫了下面的代碼段:意外的錯誤(全局變量/枚舉)
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();
}
}
}
這使我在主線錯誤。我相信這與全球變數有關。我該如何解決它?
錯字:在'main'之前移動最後一個大括號... – Reimeus
您忘了指定是什麼錯誤。 –