嗨,我正在大学学习java,我刚刚完成了一段计算BMI的代码,它是这样的,num1是公斤,num2是厘米((num1/num2)/num2)*10000; 当我向老师展示这个等式时,他告诉我这是不正确的,正确的是num1/((num2*num2)/10000); 当我测试这两行代码时,我收到了相同的结果,但他告诉我我需要证明这两行代码与 AxB 和 BxA 一样,但我还没有找到一种方法来证明它们都是相同的,但我确实知道它们如何相同。我的问题是,它们都一样吗?
如果我的体重为 70 公斤,身高为 175 厘米,那么它会在 22.9 的线上说出一些东西(请记住,这是我的方程式)。和我的老师一会是一样的。但他不相信他们是一样的。这是我的代码:
导入 javax.swing.*;导入 java.util.Scanner;
类苹果{
public static void main (String args[]) {
String fsum; /* this is a variable declaration*/
String sum; /* this is a variable declaration*/
double answer; /* this is a variable declaration*/
double num1, num2; /* this is a variable declaration*/
String anything; /* this is a variable declaration*/
Scanner Tahmid = new Scanner (System.in);/*Scanner Variable*/
System.out.println("This program was created by Tahmid Ahmed on 01/10/2013\nThis program would allow you the user to be able to calculate your BMI");
System.out.println("To continue please click enter");/*Output*/
anything = Tahmid.nextLine();/*Input as a break*/
fsum=JOptionPane.showInputDialog("Please enter weight in Kilograms (KG) " ); /*Popup box to allow weight to be entered*/
sum=JOptionPane.showInputDialog("Please enter height in Centimetres (CM) ");/*Popup box to allow height to be entered*/
num1 = Double.parseDouble(fsum);/*Conversion of String into Double*/
num2 = Double.parseDouble(sum);/*Conversion of String into Double*/
answer = num1/((num2*num2)/10000);/*<<<<<<<<-----My teachers Equation*/ /*My Equation ---- >>>>>> ((num1/num2)/num2)*10000 */
if (answer<=18){
JOptionPane.showMessageDialog(null, "Your total BMI levels are: " + answer, "You're underweight! Eat some more!", JOptionPane.INFORMATION_MESSAGE);
}
else if(answer>=25){
JOptionPane.showMessageDialog(null, "Your total BMI levels are: " + answer, "You're overweight now bro! Eat Less!", JOptionPane.INFORMATION_MESSAGE); }
else if(answer<25) {
JOptionPane.showMessageDialog(null, "Your total BMI levels are: " +answer, "You're the perfect weight! Stay that way :)", JOptionPane.INFORMATION_MESSAGE);}
}
}