importjavax.swing.JOptionPane; publicclasscalculatebodymassindex {//mainmethodpublicstaticvoidmain (string [ ] args (//enteraweightinkgstringtempstempstring .
import javax.swing.JOptionPane;
publicclasscalculatebodymassindex {
//主方法
publicstaticvoidmain (string [ ] args ) {
//Enter a weight in kg
string tempstring=joptionpane.showinputdialog (空,
' Enter a weight in kg ',' Input Dialog Demo ',
JOptionPane.QUESTION_MESSAGE;
//Enter a height in m
strings=(string ) joptionpane.showinputdialog (null,
' Enter a height in m ',' Input Dialog Demo ',
JOptionPane.QUESTION_MESSAGE;
//converttheinputstringintoadoublevalue
double weight=double.parse double (tempstring );
double height=double.parse double (tempstring );
//Convert it to BMI
doubleBMI=(weight/) height*height );
//Display the result
joption pane.show message dialog (null,' The BMI is ) )。
BMI ' in kg/m2 ';
() ) ) ) )。
() ) ) ) )。
=========================================================================================
不知道错在哪里。运算的结果错了.
程序计算BMI。 公式为重量/高度^2
我觉得是DOUBLE的问题。 但是,JAVA的水平有限.
不知道哪个大神会解决吗? 谢谢你。 ~
展开