你如何为男人和女人编码理想的体重范围

How do you code the ideal weight range for a man and a woman

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

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.");
}

}

它说 "A weight in the range..." 我需要输入包含计算理想体重范围的公式的代码。一张图表显示了与身高相对应的所有理想体重范围:

BMISurgery

感谢您提供的每一个小小的帮助,非常感谢

如果您想使用 table 中的值而不用重复使用公式来计算它们,您可以使用一些映射来存储它们

    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,你可以对最大重量做同样的事情)