使用Java在Textpad中计算体重指数
我应该在TextPad中设计一个程序来计算BMI。我无法让程序使用公式计算bmi。这是我的密码使用Java在Textpad中计算体重指数,java,textpad,Java,Textpad,我应该在TextPad中设计一个程序来计算BMI。我无法让程序使用公式计算bmi。这是我的密码 import java.util.Scanner; public class BmiCalculator { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter weight in pounds: ");
import java.util.Scanner;
public class BmiCalculator {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter weight in pounds: ");
double weightInPounds = keyboard.nextDouble();
System.out.print("Enter height in inches: ");
double heightInInches = keyboard.nextDouble();
double bmi = weightInPounds/(heightInInches * heightInInches) * 703;
System.out.println("Your body mass index is" + bmi);
}
}
输出显示:
以磅为单位输入重量:130
以英寸为单位输入高度:66
你的体重指数
当我运行程序时,没有显示bmi。我编译了程序,TextPad显示没有错误。我不知道我的代码出了什么问题。有人能在代码中找到错误吗?您误用了。您应该使用字符串连接:
System.out.println("Your body mass index is" + bmi);
或者使用使用您传递的BMI的正确格式字符串:
System.out.printf("Your body mass index is %f", + bmi);
你没有问任何问题,甚至没有抛出错误消息?你想要什么?谢谢你的帮助。我想出来了。TextPad无法读取我的体重指数方程。一旦我改变了它,我就得到了正确的输出。