我正在用Java編寫代碼,並且不斷從編譯器收到兩處錯誤,說「找不到符號」。這是我的代碼和錯誤。爲什麼我的編譯器在Java中給我這兩個錯誤?
public ComplexNumber(float a, float b){
a = real;
b = imaginary;
}
這是兩個錯誤。
ComplexNumber.java:22: error: cannot find symbol
a = real;
^
symbol: variable real
location: class ComplexNumber
ComplexNumber.java:23: error: cannot find symbol
b = imaginary;
^
symbol: variable imaginary
location: class ComplexNumber
2 errors
任何意見是非常感謝。提前致謝!
你的程序中定義了'real'和'imaginary'哪裏有? – 2014-11-05 20:57:14
由於'real'和'imaginary'沒有在你的類中定義,我相信你應該把你的參數值分配給某個字段,而不是寫入它們。 – Habib 2014-11-05 20:57:45