0

我正在开发一个项目,只是为了测试 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
4

3 回答 3

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

于 2013-07-17T13:38:23.397 回答
1

从方法中删除main方法。如果您main用作应用程序入口点,则返回类型为void

public static void main(String[] args) {
于 2013-07-17T13:39:22.433 回答
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;
}
于 2013-07-17T13:38:25.287 回答