here code. reason bmi not calculated correctly. when check output on calculator : (10/((10/100)^2))) 1000, in program, 5. i'm not sure doing wrong. here code:
import javax.swing.*; public class bmi { public static void main(string args[]) { int height; int weight; string getweight; getweight = joptionpane.showinputdialog(null, "please enter weight in kilograms"); string getheight; getheight = joptionpane.showinputdialog(null, "please enter height in centimeters"); weight = integer.parseint(getweight); height = integer.parseint(getheight); double bmi; bmi = (weight/((height/100)^2)); joptionpane.showmessagedialog(null, "your bmi is: " + bmi); } }
^ in java not mean raise power. means xor.
you can use java's math.pow()
and might want consider using double instead of int—that is:
double height; double weight; note 199/100 evaluates 1.
Comments
Post a Comment