我写了以下代码:
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)
有一个拼写错误:: 更改代码如下::
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 :(得分:2)
您的大括号不匹配,请在}
之前添加一个右大括号main
,并从最后一行中删除一个大括号。