-
Notifications
You must be signed in to change notification settings - Fork 627
/
Copy pathBMI_calculator.java
40 lines (31 loc) · 1.13 KB
/
BMI_calculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
public class BMICalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("BMI Calculator");
System.out.println("---------------");
System.out.print("Enter your weight in kilograms: ");
double weight = scanner.nextDouble();
System.out.print("Enter your height in meters: ");
double height = scanner.nextDouble();
double bmi = calculateBMI(weight, height);
System.out.println("\nYour BMI is: " + bmi);
interpretBMI(bmi);
scanner.close();
}
public static double calculateBMI(double weight, double height) {
return weight / (height * height);
}
public static void interpretBMI(double bmi) {
System.out.print("BMI Interpretation: ");
if (bmi < 18.5) {
System.out.println("Underweight");
} else if (bmi < 25) {
System.out.println("Normal Weight");
} else if (bmi < 30) {
System.out.println("Overweight");
} else {
System.out.println("Obese");
}
}
}