算BMI值

import javax.swing.JOptionPane;
public class Health {
    public static void main(String[] args){
        double weight,height;
        String input = JOptionPane.showInputDialog(null,"请输入您的体重","对话框",JOptionPane.QUESTION_MESSAGE);
        String input1 = JOptionPane.showInputDialog(null,"请输入您的身高","对话框",JOptionPane.QUESTION_MESSAGE);
        double a = Double.parseDouble(input);
        double b = Double.parseDouble(input1);
        weight = a * 0.45359237;
        height = b * 0.0254;
        System.out.println("BMI is " + (int)(weight / Math.pow((height),2) * 100) / 100.00);
    }
}

BMI值通过体重(公斤)除以身高(米)的平方得到,编写程序,提示输入用户体重(磅)和身高(英寸),然后显示BMI

一磅等于0.45359237公斤,一英寸等于0.0254米。

posted @ 2014-08-06 17:36  Amoxicil  阅读(149)  评论(0编辑  收藏  举报