[英]Java command prompt compile error
I started learning Java lately, and trying to make my first program based on book which is the "Hello World" program. 最近,我开始学习Java,并尝试根据本书的“ Hello World”程序制作我的第一个程序。 After writing the script on notepad, i try to compile it on the command prompt and then this notice appeared. 在记事本上编写脚本后,我尝试在命令提示符下对其进行编译,然后出现此通知。
first I type: javac javaCode.java 首先我输入:javac javaCode.java
then there a notice said: 然后有一个通知说:
javaCode.java:2: error: <identifier> expected
public class static void main(string[] args) {
^
javaCode.java:6: error: reached end of file while parsing
}
^
2 errors
I don't have any ideas what going on here so please give detailed information and how to fix this thing. 我不知道这是怎么回事,因此请提供详细信息以及如何解决此问题。
public class static void main(string[] args)
Remove class 删除课程
public static void main(string[] args)
class
is different from method. class
与方法不同。 main
method syntax doesn't contain class
. main
方法的语法不包含class
。
Your main method needs to go inside a class: Java won't let you do things any other way. 您的主要方法需要放入一个类中:Java不允许您以其他任何方式进行操作。
Try: 尝试:
public class HelloWorld{
public static void main (String[] args){
//your code goes here
}
}
this the basic structure for a simple program like this. 这是一个简单程序的基本结构。
the class identifier, has to be on the declaration of the class. 类标识符,必须在类的声明上。
public class Caculator {
public static void main(String[] args) {
// Your code here
}
}
It probably should be: 可能应该是:
public class JavaCode {
public static void main(String[]args){
}
}
That should do it. 那应该做。 ;) ;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.