OOP-JAVA Practical 4
- Aim: Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI.
- Code:
import java.util.Scanner; public class practical4{ public static void main(String args[]){ double w,h,bmi; Scanner weight =new Scanner(System.in); Scanner height =new Scanner(System.in); System.out.println("Enter weight in pounds"); w=weight.nextDouble(); System.out.println("Enter height in inches"); h=height.nextDouble(); w*=0.45359237; h*=0.0254; bmi=(w/(h*h)); System.out.println("BMI:"+bmi); } }
- Output:
Comments
Post a Comment