您是否在此代碼中看到任何錯誤?在沒有效果的情況下,它會返回一個NaN。它使用了Java:算術
public class Method2 extends GUIct1
{
double x=0,y=0;
void settype1 (double conv1)
{
x = conv1;
}
void settype2 (double conv2)
{
y = conv2;
}
double conversion (double amount)
{
double converted = (amount*y)/x;
return converted;
}
}
辦法,我已經改變了設置部位
Method2 convert = new Method2(); \\ method is called
.....
convert.settype1(j);
.....
。 ...
double x = convert.conversion(i);
System.out.println(x);
您的get方法應該被命名爲set。 – unholysampler 2011-03-08 19:05:47
代碼片段不完整。請更新它。 – asgs 2011-03-08 19:05:51
您正在初始化'x',用'x'分隔的類中的0 - 您期望會發生什麼?這就像留下燃料和火柴,希望沒有人一起使用它們) – schnaader 2011-03-08 19:06:33