我是一個java新手,寫了一段代碼,有關(guān):攝氏度和華氏度之間的互相轉(zhuǎn)化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;}}}//問題:為何出現(xiàn)錯誤?我import了?。?!其中cToF和fToC是我另外寫的函數(shù),但是沒有和上面代碼段放在一起,而是新建了一個: 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;
}
}然后運行主函數(shù)時cToF(she1);和fToC(hua2);報錯:The method cToF(double) is undefined for the type TestCToFandFToC為什么會這樣???謝謝!
java中怎么引用自己寫的函數(shù)
寶慕林4294392
2019-04-10 17:15:42