2014-10-01 79 views
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); 

      } 

    } 

每当我正在执行程序时,我都会收到这些错误。不需要代码的答案..只是想知道为什么我得到这些错误。为什么我得到不兼容的类型错误?

回答

3

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

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

你所得到的错误,因为methodC不返回任何一个双返回值,但你试图将其返回值分配给f

相关问题