if、else if、else 语句的未知错误

Unknown error on if, else if, else statement

我的最后一个 else 语句在 if、else if 和 else 的字符串中不断出现语法错误,我无法弄清楚为什么,也找不到任何地方告诉我真正令人困惑的是我做了什么这种类型的 if else 语句设置之前从未遇到过这个问题。我曾尝试使用 2 个编码程序(JCreator 和 Eclipse),但它们都给我一个错误像这样的,不需要 if 语句,就像最后一个一样。

    import java.util.Scanner;

    public class Hotel 
    {
        public static void main(String[] args)
        {
            String answer = "";
            Scanner keyboard = new Scanner(System.in);
            GuestInterface go = new GuestInterface();
            PassswordField hotel = new PassswordField();

            System.out.println("do you wish do acces the guest interface or the hotel staff interface? ");
            System.out.println("Hint: hotel staff -or- guest");
            answer = keyboard.nextLine();
            if(answer.equalsIgnoreCase("hotel Staff"))
            {
                System.out.println("Enter username");
                answer = keyboard.nextLine();
                hotel.readPassword("Enter Passsword \n ");
                System.out.print("\n" + "incorect Password");
                System.out.println("System will now shut down");
                System.exit(0);
            }
            else
            if(answer.equalsIgnoreCase("Guest"))
            {
                go.run();
            }
            else //error throws on this statment
            {
                System.out.println("uncompatible responce");
                System.out.println("System ato shut down activated");
                System.exit(0);
            }
        }
    }

你在这一行的末尾写了一个;:

if(answer.equalsIgnoreCase("Guest"));

所以这是一个单独的 if 语句。在那之后,你从这个开始:

        {
            go.run();
        }
        else //error throws on this statment
        {
            // (...)
        }

这对编译器没有意义,因为它不是以 if 语句开始的
删除 ; 以解决错误。