0
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);

            }

    }

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

4

3 回答 3

3

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

于 2014-10-01T18:25:02.583 回答
0

因为methodCreturnvoid和你的分配期望一个双倍的返回值

将您的方法签名更改为

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;
}
于 2014-10-01T18:25:12.370 回答
0

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

于 2014-10-01T18:25:32.407 回答