编译错误“否则没有”

时间:2017-05-25 13:26:12

标签: java

import java.util.*;

public class ttttt
{
    public static void main (String [] args)
    {
        Scanner kb = new Scanner(System.in);
        System.out.println("Please enter a grade >> ");
        String grade = kb.nextLine();

        if (grade.equalsIgnoreCase("High Distinction"))
        {
            System.out.println("Very well done");
        }
        else if (grade.equalsIgnoreCase("Pass");
        {
            System.out.println("well done");
        }
        else if (grade.equalsIgnoreCase("not pass");
        {
            System.out.println("need to work harder");
        }
        else
        {
            System.out.println("Questions are a good thing");
        }
    }
}

我收到错误“Else without if”。这里有什么问题?我正确地使用了分号。我忘记了语法吗?

2 个答案:

答案 0 :(得分:4)

else if (grade.equalsIgnoreCase("Pass");最后不需要;

答案 1 :(得分:0)

你在这里缺少一个括号:

 else if (grade.equalsIgnoreCase("not pass");
  {
     System.out.println("need to work harder");
  }

看起来你缺少一些括号。