Java 使用阵列的温度转换不工作?

Java 使用阵列的温度转换不工作?,java,Java,所以我试图将数组中的数字从华氏转换成塞尔修斯;我没有得到任何错误,但我的数字肯定是不对的。这是我的密码: package lab7q2; public class Lab7Q2 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int[] tempList = {21

所以我试图将数组中的数字从华氏转换成塞尔修斯;我没有得到任何错误,但我的数字肯定是不对的。这是我的密码:

package lab7q2;

public class Lab7Q2 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here


    int[] tempList = {212, 95, 64, 32, 0, -12, -25};

    for (int i = 0; i < tempList.length; i++) {
        System.out.format("temp in F %4d  temp in C %6.2f \n", + tempList[i], tempFtoC(i));
    }


}

public static double tempFtoC (int tempList) {

    double tempC = ((tempList - 32)*5)/9;
    return tempC;
    }

}

有人能告诉我为什么转换不对吗?我的方法设置不正确吗?(编程新手,所以请不要对我太粗暴…

您正在转换
i
,而不是
templast[i]
,因此您应该将格式语句更改为

System.out.format("temp in F %4d  temp in C %6.2f \n", + tempList[i], tempFtoC(tempList[i]));

仔细检查您在转换方法中传递的内容
System.out.format("temp in F %4d  temp in C %6.2f \n", + tempList[i], tempFtoC(tempList[i]));