【问题标题】:Java Error: <Identifier> expected Public Class [duplicate]Java 错误:<Identifier> 预期的公共类 [重复]
【发布时间】:2019-02-06 14:04:38
【问题描述】:

我刚开始学习 Java,尝试使用“Javac”编译以下源代码时出现以下错误:

"C:\Java>javac 99Bottles.java

99Bottles.java:1:错误:预期

public class 99Bottles { //公开类“99Bottles”

似乎无法确定这是语法错误还是我遗漏了什么?任何建议将不胜感激,谢谢

 public class 99Bottles { //open Class "99Bottles"
    public static void main (String[] args) { //Open main method
        int Beernum = 99; //delcate intergar called "Beernum" with value of 99
        String word = "bottles"; //delcare the string "word" with a value of "bottles"

        System.out.println(Beernum + " " + word + "of beer on the walL");  //prints
        System.out.println(Beernum + " " + word + "of beer"); //prints
        System.out.println("you take one down"); //prints
        System.out.println("you pass it around"); //prints

        Beernum = Beernum - 1; //subtract 1 from the value of "Beernum"

        if (Beernum > 0) { //Check if Beernum is greater than 0
                System.out.println(Beernum + " " + "of beer on the wall"); //prints
        } else { //if the if statement is not true run this
                System.out.println("no more bottles of beer on the wall"); //prints
            }        

    }
}

【问题讨论】:

  • 我不完全确定,但我认为类名不能以数字开头。尝试简单地将class 99Bottles 更改为class Bottles
  • 类名不能以数字开头

标签: java class methods syntax public


【解决方案1】:

标识符是 Java 字母和 Java 的无限长度序列 数字,其中第一个必须是 Java 字母。

类名是一个标识符。

【讨论】:

    猜你喜欢
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多