我是一个java新手,写了一段代码,有关:摄氏度和华氏度之间的互相转化
package method;
import method.HuaShe;
public class TestCToFandFToC {
public static void main(String[] args){
System.out.println("摄氏 华氏 华氏 摄氏");
for(int i = 1;i <= 10;i++){
double she1 = 40.0;
double hua1 = cToF(she1);
double hua2 = 120.0;
double she2 = fToC(hua2);
System.out.println(she1 + " " + hua1 + " " + hua2 + " " + she2);
she1 -= 1;
hua2 -= 10;
}
}
}
//问题:为何出现错误?我import了啊!!
其中cToF和fToC是我另外写的函数,但是没有和上面代码段放在一起,而是新建了一个:
package method;
public class HuaShe {
static double cToF(double c){
double ft = (9.0 / 5) * c + 32;
double f = (int)(ft * 100) / 100.0;
return f;
}
//--------------------------------------
static double fToC(double f){
double ct = (f - 32) / (9.0 / 5);
double c = (int)(ct * 100) / 100.0;
return c;
}
}
然后运行主函数时
cToF(she1);和fToC(hua2);报错:
The method cToF(double) is undefined for the type TestCToFandFToC
为什么会这样???
谢谢!