【问题标题】:How do you code the ideal weight range for a man and a woman你如何编码男女的理想体重范围
【发布时间】:2017-01-30 09:59:40
【问题描述】:

当你输入你的身高时,我已经编码了男性和女性的理想体重。

import java.util.Scanner;
public class height
{
public static void main (String []args)
{
    int Feet, Inches, Totalinches, Maleweight, Femaleweight;
    Scanner scan = new Scanner (System.in);

    System.out.println ("Please enter your height in feet and inches...");

    System.out.println ("Feet: ");
    Feet = scan.nextInt();
    System.out.println ("Inches: ");
    Inches = scan.nextInt();

    Totalinches = Feet*12 + Inches; 
    Maleweight = 106 + (Totalinches - 60)*6;
    Femaleweight = 100 + (Totalinches - 60)*5;

    System.out.println ("The ideal weight for a " + Feet + " foot " + Inches +  " male is " + Maleweight + " pounds.");

    System.out.println ("A weight in the range  to  is okay.");

    System.out.println ("The ideal weight for a " + Feet + " foot " + Inches + " female is " + Femaleweight + " pounds.");

    System.out.println ("A weight in the range  and  is okay.");
}

}

上面写着“范围内的重量...”我需要输入包含计算理想重量范围的公式的代码。在这里可以找到一张图表,说明与身高相对应的所有理想体重范围:

BMISurgery

感谢大家的帮助,非常感谢

【问题讨论】:

    标签: java height


    【解决方案1】:

    如果您想使用该表中的值而不需要重复使用公式来计算它们,您可以使用一些地图来存储它们

        Map<Integer, Integer> minimumMaleWeight = new HashMap<>();
        minimumMaleWeight.put(54, 63);
        minimumMaleWeight.put(55, 68);
        minimumMaleWeight.put(56, 74);
        minimumMaleWeight.put(57, 79);      
    
        Map<Integer, Integer> maximumMaleWeight = new HashMap<>();
        maximumMaleWeight.put(54, 77);
        maximumMaleWeight.put(55, 84);
        maximumMaleWeight.put(56, 90);
        maximumMaleWeight.put(57, 97);
    
        System.out.println(minimumMaleWeight.get(Totalinches));
        System.out.println(maximumMaleWeight.get(Totalinches));
    

    如果您想使用公式来计算它们,看起来向上取整 5.4*Totalinches-228.7 可能有效(here is where I got the numbers,您可以为最大重量做同样的事情)

    【讨论】:

    • 非常感谢 deadyr 帮助我找到体重范围的最小数量。如果这很麻烦,我很抱歉,但您能解释一下如何获得最大重量的公式吗?我不确定您是如何获得诸如“(54, 63),(55, 68)”之类的数字以及如何对其进行线性拟合以找到最大重量的。我才开始学习java几个星期。再次感谢您的辛勤努力。
    • Wolframalpha 是一个可以为您运行各种数学的网站,只需给它数字,它就会为您进行线性拟合。我从表中得到了数字,例如男性 4' 6" (=54'') ----> 63 - 77 lbs. 4' 7" (=55'') -------- > 68 - 84 磅。 4' 8" (=56'')----------->74 - 90 磅。这是最大重量的线性拟合:wolframalpha.com/input/…
    猜你喜欢
    • 2021-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多