这个问题在这里已有答案:
我刚刚开始学习Java,当尝试使用“Javac”编译下面的源代码时,我收到以下错误:
“C:\ Java> javac 99Bottles.java
99Bottles.java:1:错误:预期
public class 99Bottles {// open Class“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
}
}
}
标识符是无限长度的Java字母和Java数字序列,第一个必须是Java字母。
类名是标识符。