Java 编译器错误消息“”是什么意思?预计”意思是?

发布于 2024-11-30 12:15:09 字数 478 浏览 2 评论 0原文

class if{
    public static void main (String args[]){
        int x = 9;
        if (x <= 9){
            System.out.println("Yay");
        }else{
            System.out.println("Yay");
            }
        }
    }

我从编译器运行它,使用 Notepad++ 作为文本编辑器。我在编译器中收到错误消息 ;预期类如果。还有另一个错误,指出表达式非法开始。 以及说错误“;”预期。我总共有9个错误。

我确保匹配所有 {}()。甚至刮掉了程序并再次尝试,结果相同。

class if{
    public static void main (String args[]){
        int x = 9;
        if (x <= 9){
            System.out.println("Yay");
        }else{
            System.out.println("Yay");
            }
        }
    }

I'm running this from the compiler, using Notepad++ as the text editor. And I am getting an error in the compiler saying <identifier> expected class if. And another error saying illegal start of expression.
As well as saying error ";" expected. I have a total of 9 errors.

I made sure to match all the {} and (). Even scraped the program and tried again with the same results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浪菊怪哟 2024-12-07 12:15:09

if 是 Java 中的保留关键字(如 if 语句中所示),因此不是合格的类名。为您的类选择另一个名称,例如 IfTesting

按照惯例,所有类名都以大写字母开头。有关有效 Java 标识符和无效 Java 标识符的完整详细信息,请参见 Java 语言规范。简而言之,它不能是 关键字truefalsenull

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.

海风掠过北极光 2024-12-07 12:15:09

你不应该将一个类称为“if”。它是一个保留的 Java 关键字(顺便说一句,您在程序中使用它)。

此外,按照惯例,Java 中所有类都以大写字母开头。

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.

温柔女人霸气范 2024-12-07 12:15:09

您不能使用关键字命名您的类,甚至不能命名变量。

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

不可一世的女人 2024-12-07 12:15:09

你不能命名你的类 if,因为它是一个关键字。查看了解更多示例。

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

孤独患者 2024-12-07 12:15:09

另外,它是 (String[] args)

不是 (String args[])

Also, it's (String[] args)

Not (String args[])

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文