bmijava,JAVA:BMI计算器使用

博主刚接触Java,尝试用构造函数、公共实例方法和toString方法构建简单BMI计算器,给出了部分代码但不知如何完成,希望得到帮助,解决方案指出BMI是体重(千克)除以身高(米)的平方。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am very new to java trying to build a simple BMI calculator using a constructor, a public instance method and a toString method.

public class BMI {

public BMI(String name, double height, double weight){

}

public String getBMI() {

return (weight/height);

}

public String toString() {

return name + "is" + height + "tall and is " + weight +

"and has a BMI of" + getBMI() ;

}

public static void main(String[] args) {

}

i don't really know what i'm doing, so all help is appreciated. If you know how to complete this and can show me a main method which can demonstrate how to use it that would be even more appreciated.

thanks :)

解决方案

You already have a code so I'll just mention that BMI is weight (in kg) divided by height (in m) squared

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值