Java program ComputeAndInterpretBMI.java, to let the user enter weight, feet, and inches and calculate and interpret the user BMI whether underweight, normal, overweight or obese.
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> */<br /><br />import java.util.Scanner;<br /><br />public class ComputeAndInterpretBMI {<br /> public static void main (String [] args) {<br /> Scanner input = new Scanner(System.in);<br /> //Prompt the user to enter weight in pounds<br /> System.out.print("Enter weight in pounds: ");<br /> double weight = input.nextDouble();<br /> //Prompt the user to enter height in feet and inches<br /> System.out.print("Enter feet: ");<br /> double feet = input.nextDouble();<br /> System.out.print("Enter inches: ");<br /> double inches = input.nextDouble();<br /> double height = (feet * 12) + inches;<br /> final double KILOGRAMS_PER_POUND = 0.45359237; // Constant<br /> final double METERS_PER_INCH = 0.0254; // Constant<br /> //Compute BMI<br /> double weightInKilograms = weight * KILOGRAMS_PER_POUND;<br /> double heightInMeters = height * METERS_PER_INCH;<br /> double bmi = weightInKilograms / (heightInMeters * heightInMeters);<br /> // Display result<br /> System.out.println("BMI is " + bmi);<br /> if (bmi < 18.5) {<br /> System.out.println("Underweight");<br /> } else if (bmi < 25) {<br /> System.out.println("Normal");<br /> } else if (bmi < 30) {<br /> System.out.println("Overweight");<br /> } else {<br /> System.out.println("Obese");<br /> }<br /> }<br />}<br /> |
Sample run |
Click here to see other solutions to Introduction to Java Programming.