Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Else If语句-代码不工作?_Java_Variables_If Statement_Conditional Statements - Fatal编程技术网

Java Else If语句-代码不工作?

Java Else If语句-代码不工作?,java,variables,if-statement,conditional-statements,Java,Variables,If Statement,Conditional Statements,我的代码非常基础,因为我本周开始使用Java。然而,我似乎无法让我的else if语句起作用。这是我的密码: import java.util.Scanner; class RestaurantMain { public static void main(String[] args) { //Variables// int choice; //EndVariables// Scanner in = new Sca

我的代码非常基础,因为我本周开始使用Java。然而,我似乎无法让我的else if语句起作用。这是我的密码:

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,我的else-if语句不是这些语句在另一个文件中特别有效

如果可以的话,谢谢你的帮助

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

移除;从该代码中

删除if和elseif行中与{之间的分号,如if choice==1{。我猜你正在学习一些教程。我建议你多注意一些像这样的小细节。我把我的答案转换成了一条评论,因为这个问题是一个简单的印刷错误,应该关闭,而不是回答。@DavidWallace只是看着其他人带着战利品离开……然后分配给我nt choice;在声明时有一定的价值。@Poldie,然后当问题被关闭和删除时,他们会失去他们的战利品。这里也有关于什么问题是受欢迎的和不受欢迎的指导原则。根据这些指导原则,这个问题是不受欢迎的。所以我用我的10点魔法独角兽点数做了正确的事情。非常感谢!我确实需要要注意这一点!我可以用Python编写代码,所以这对我来说是全新的,哈哈