我正在研究一个项目,只是为java开发人员测试eclipse IDE。我是java的新手,所以我想知道它为什么不起作用,因为我已经知道该怎么做了。这是代码:
public class eclipse {
public static double main(String[] args) {
// TODO Auto-generated method stub
final double average(double number, double number2)
{
double number3 = (number + number2)/2;
return number3;
}
final double suk(double number4, double number5)
{
double number6 = number4 + number5;
return number6;
}
final double differenck(double number7, double number8)
{
double number9 = number7 - number8;
return number9;
}
final double produck(double number10, double number11)
{
double number12 = number10*number11;
return number12;
}
}
}
这是出现的错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "(", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected
Void methods cannot return a value
Syntax error on token "(", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected
Void methods cannot return a value
Syntax error on token "(", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected
Void methods cannot return a value
Syntax error on token "(", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected
Void methods cannot return a value
答案 0 :(得分:1)
您正在使用main方法编写所有方法。请从main
方法中删除所有方法
public static void main(String[] args) {
//do something
}
final double average(double number, double number2)
{
double number3 = (number + number2)/2;
return number3;
}
final double suk(double number4, double number5)
{
double number6 = number4 + number5;
return number6;
}
final double differenck(double number7, double number8)
{
double number9 = number7 - number8;
return number9;
}
final double produck(double number10, double number11)
{
double number12 = number10*number11;
return number12;
}
return
种类main
方法应为void
答案 1 :(得分:1)
从main
方法中删除方法。如果您使用main
作为应用程序入口点,则返回类型为void
public static void main(String[] args) {
答案 2 :(得分:0)
它们需要在main方法之外,main方法的返回类型也是void:
public static void main(String[] args) {
//code
}
final double average(double number, double number2)
{
double number3 = (number + number2)/2;
return number3;
}
final double suk(double number4, double number5)
{
double number6 = number4 + number5;
return number6;
}
final double differenck(double number7, double number8)
{
double number9 = number7 - number8;
return number9;
}
final double produck(double number10, double number11)
{
double number12 = number10*number11;
return number12;
}