很抱歉打扰你们,我是编程新手,对此程序遇到了问题。
import javax.swing.*;
import java.text.*;
import java.util.*;
public class Project13{
public static void main(String [] args){
String heightStr;
String weightStr;
int height;
int weight;
int bmi;
DecimalFormat df = new DecimalFormat("0");
heightStr = JOptionPane.showInputDialog(null,"Enter height in centimetres:");
height = Integer.parseInt(heightStr);
weightStr = JOptionPane.showInputDialog(null,"Enter weight in kilograms:");
weight = Integer.parseInt(weightStr);
int bmi = weight/ ((height/ 100.0)* (height/ 100.0));
JOptionPane.showMessageDialog(null,"The BMI is "+ bmi +" .");
}
}
当我尝试对此进行编译时,会收到以下错误消息:
谁能发现问题?
另外,哪种程序是编写Java的最佳选择?我目前使用Crimson Editor,但是每次使用它都需要进行大量设置。
谢谢!
*******编辑***************
我从BMI中删除了int,有损转换错误仍然存在。有想法该怎么解决这个吗?
最佳答案
这是问题所在:
int bmi = weight/ ((height/ 100.0)* (height/ 100.0));
您已经声明了bmi以及其他变量。您应该改为设置bmi。
bmi = weight/ ((height/ 100.0)* (height/ 100.0)); //take out the "int"