Basically I need to write an application to calculate BMI using the formula;
BMI = w/ (h/100) 2
The user must type in her height in centimeters and weight in kilograms, and the computer prints out the user's BMI.
import java.util.Scanner;
import java.text.DecimalFormat;
public class BMI {
public static void main(String args[ ]){
double pound = .453592;
double inches = 2.54;
Scanner scan = new Scanner(System.in);
System.out.println("Enter in your weight: ");
double weight = scan.nextDouble();
System.out.println("Enter in your height: " );
double height = scan.nextDouble();
weight = weight * pound ;// Converts pounds to kilograms
height = height * inches ;// Converts inches to centimeters
double BMI = weight/(height*height);// Computes users BMI
DecimalFormat fmt = new DecimalFormat("0.00");// Rounds answer to 2 decimal places.
System.out.println("Your Body Mass Index is: " + fmt.format(BMI));
I keep getting "Your BMI is: 0". What am I doing wrong? Any suggestions, thanks in advance.
Also I'll be using JOptionPane.showInputDialog() to get user input and JOptionPane.showMessageDialog() to print the results to the user.