gpt4 book ai didi

java - 如何计算男性和女性的理想体重范围

转载 作者:行者123 更新时间:2023-11-30 07:08:28 26 4
gpt4 key购买 nike

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

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

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

最佳答案

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

    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 ,您可以对最大重量执行相同的操作)

关于java - 如何计算男性和女性的理想体重范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39628622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com