What does the Java compiler error message “ expected” mean?

后端 未结 5 906
眼角桃花
眼角桃花 2021-01-19 02:26
class if{
    public static void main (String args[]){
        int x = 9;
        if (x <= 9){
            System.out.println(\"Yay\");
        }else{
                    


        
相关标签:
5条回答
  • 2021-01-19 03:01

    if is a reserved keyword in Java (as seen in your if statement), and is thus not an eligible class name. Choose another name for your class, like IfTesting.

    By convention, all class names start with an upper-case letter. The full details for what is and isn't a valid Java identifier are found in the Java Language Specification. In short, it can't be a keyword, true, false, or null.

    0 讨论(0)
  • 2021-01-19 03:11

    You shouldn't call a class "if". It's a reserved Java keyword (that you're using in your program, BTW).

    Furthermore, by convention, all classes start with an uppercase letter in Java.

    0 讨论(0)
  • 2021-01-19 03:13

    You can't name your class if, as it's a keyword. Check this for more examples.

    0 讨论(0)
  • 2021-01-19 03:18

    You cannot name your class or even a variable with a keyword.

    0 讨论(0)
  • 2021-01-19 03:19

    Also, it's (String[] args)

    Not (String args[])

    0 讨论(0)
提交回复
热议问题