我收到此编译错误:
Solution.java:9: error: ';' expected
boolean isEVen(){
^
码:
import java.util.Scanner;
public class Solution {
public static void main (String[] args){
Scanner s = new Scanner(System.in);
int n = s.nextInt();
boolean isEVen(){
return n%2==0;
}
if (isEVen() && n<=5 && n>=2){
System.out.println("Not Weird");
}else{
if(!isEVen()){
System.out.println("Weird");
}else{
if(isEVen() && n>=6 && n<=20){
System.out.println("Weird");
} else{
if (isEVen() && n>20){
System.out.println("Not Weird");
}
}
}
}
}
}
我应该把分号放在哪里?
最佳答案
如下更新代码。
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
if (isEVen(n) && n <= 5 && n >= 2) {
System.out.println("Not Weird");
} else {
if (!isEVen(n)) {
System.out.println("Weird");
} else {
if (isEVen(n) && n >= 6 && n <= 20) {
System.out.println("Weird");
} else {
if (isEVen(n) && n > 20) {
System.out.println("Not Weird");
}
}
}
}
}
static boolean isEVen(int n) {
return n % 2 == 0;
}
}
关于java - 出现编译错误: “java:9: error: ' ;' expected” ;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61382363/