为什么我会遇到不兼容的类型错误?

时间:2014-10-01 18:23:55

标签: java recursion jcreator

public static void main(String[] args) {

   double f = methodC(1234); **//error is on this line & pointing the opening bracket**
   System.out.println(f);

}

    public static void methodC(double a){
        if (a==0){
           System.out.println(0);
    }
            else{
                double n= a/10;
                double r= a%10;
                System.out.println(r);

            }

    }

每当我做一个程序时,我都会遇到这些错误。不需要代码的答案..只是想知道我为什么会收到这些错误。

3 个答案:

答案 0 :(得分:3)

methodC没有返回值。它应该为作业返回一个双精度值 - double f = methodC(1234)才能正常工作。

答案 1 :(得分:0)

因为methodC返回void并且您的作业需要双重返回值

将方法签名更改为

public static double methodC (double a) {
    .
    .
    .
    //make it return a double value as a double value is expected by the 
    //variable on the left hand side of the assignment.
    return doubleValue;
}

答案 2 :(得分:0)

您收到错误是因为methodC没有返回任何内容,但您尝试将其返回值分配给f

相关问题