有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么要用下面的代码将320.04号打印到控制台上?

我读了下面的代码很多次,我不明白为什么我在控制台上得到320.04。有人能帮我弄清楚吗

package com.heshanshivantha;

public class Main {

    public static void main(String[] args) {

        calcFeetAndInchesToCentimeters(126);
    }

    public static double calcFeetAndInchesToCentimeters(double feet, double inches) {
        if (feet >= 0 && inches >= 0 && inches <= 12) {
            System.out.println(feet * 12 * 2.54 + inches * 2.54);
            double centimeters = feet * 12 * 2.54 + inches * 2.54;
            System.out.println(feet + " feet " + inches + " inches = " + centimeters + " cm");
            return centimeters;
        } return -1;
    }

   public static double calcFeetAndInchesToCentimeters(double inches) {
        if (inches >= 0) {
            int feet =(int) (inches / 12);
            int remainingInches =(int) (inches % 12);
            System.out.println(inches + " inches is equal to " + feet + " feet and " + remainingInches + " inches");
            return calcFeetAndInchesToCentimeters(feet, remainingInches);
        } return -1;
   }

}

126.0英寸等于10英尺6英寸 320.04 10.0英尺6.0英寸=320.04厘米

进程已完成,退出代码为0


共 (0) 个答案