Java Else If语句 - 代码不起作用?

时间:2015-03-24 00:43:08

标签: java variables if-statement conditional-statements

我的代码非常基础,因为我本周开始使用Java。但是,如果陈述有效,我似乎无法得到我的其他东西。这是我的代码:

import java.util.Scanner;

class RestaurantMain {
    public static void main(String[] args)
    {
        //Variables//
        int choice;

        //EndVariables//
        Scanner in = new Scanner(System.in);

        System.out.println("Welcome to the Cooper's restaurant system!");
        System.out.println("How can I help?");
        System.out.println("");
        System.out.println("1. Customer System");
        System.out.println("2. Management System");
        System.out.println("");
        System.out.println("");
        System.out.println("Which option do you choose: ");
        choice = in.nextInt();

        if (choice == 1); {
            System.out.println("You have entered the customer system!");
        }

        else if (choice == 2); {
            System.out.println("You have entered the management system!");
        }

    }
}

这是我得到的错误:

RestaurantMain.java:26: error: 'else' without 'if'
            else if (choice == 2); {
            ^
1 error

Tool completed with exit code 1

我不知道该怎么做。我正在使用TextPad,我已经使用了其他if语句(不是这些语句)在另一个文件中工作。

感谢您的帮助,如果可以的话!

1 个答案:

答案 0 :(得分:0)

if (choice == 1); {
   System.out.println("You have entered the customer system!");
}

从该代码中删除;