[英]Error: Main method not found in class... why am I getting this?
[英]“Main method not found in class…” but it is there ?? so why the error?
我希望有人可以在这里为我提供帮助。 我收到错误消息:
Main
在课堂上没有找到方法Pythag
,请确定的主要方法为:public static void main(String[] args)
但是正如您在下面的代码中看到的那样,它在那里? 那么为什么会出错呢? 我的Eclipse Java EE IDE中的类似乎经常发生这种情况。
public class Pythag {
// All Java applications have a main() method.
// This one does a simple Pythagorean calculation.
public static void main(String[] args) {
// Declare fields and initialise values(input).
int firstNum = 17;
int secondNum = 6;
int answer;
// Do the calculation (process).
//
answer = (firstNum * firstNum) + (secondNum * secondNum);
// Display the results (output).
//
System.out.println("The square of the hypotenuse is "
+ "equal to the sum of the squares "
+ "of the other two sides.");
System.out.println("For example...");
System.out.println(answer + " = " + firstNum + " squared + "
+ secondNum + " squared.");
}
}
我只是尝试验证我的代码,然后运行正常? 不知道问题出在哪里还是为什么不起作用,但是验证代码似乎可以解决问题,所以我们去了?
假设在名为Pythag.java的文件中定义了此类,则可以像这样编译和运行该类:
$ javac Pythag.java
$ java Pythag
The square of the hypotenuse is equal to the sum of the squares of the other two sides.
For example...
325 = 17 squared + 6 squared.
该输出是通过将您的代码示例直接复制到名为Pythag.java的文件中而不进行编辑而生成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.