-
Notifications
You must be signed in to change notification settings - Fork 0
/
BmiCalculator.java
84 lines (64 loc) · 2.58 KB
/
BmiCalculator.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package programs;
import java.util.Scanner;
public class BmiCalculator {
public static void main(String[] args)
{
Scanner obj1 = new Scanner(System.in);
System.out.print("Enter your age ");
int age = obj1.nextInt();
Scanner sc = new Scanner(System.in);
System.out.print("Input weight in kilogram: ");
double weight = sc.nextDouble();
System.out.print("Input height in meters: ");
double height = sc.nextDouble();
double BMI = weight / (height * height);
System.out.println("\nThe Body Mass Index (BMI) is " + BMI + " kg/m2\n");
if (BMI < 18.5) {
System.out.println("Your BMI is : " + BMI + " kg/m2" + " | Classification :" + " Under weight");
}
else if (BMI <= 18.5 || BMI <= 24.9) {
System.out.println("Your BMI is : " + BMI + " kg/m2" + " | Classification :" + " Normal");
}
else if (BMI <= 25 || BMI <= 29.9) {
System.out.println("Your BMI is : " + BMI + " kg/m2" + " | Classification :" + " Over weight");
}
else if (BMI <= 30 || BMI <= 34.9) {
System.out.println("Your BMI is : " + BMI + " kg/m2" + " | Classification :" + " Obesity (Class 1)");
} else if (BMI <= 35 || BMI <= 39.9) {
System.out.println("Your BMI is : " + BMI + " kg/m2" + " | Classification :" + " Obesity (Class 2)");
}
else if (BMI > 40) {
System.out.println("Your BMI is : " + BMI + " kg/m2" + " | Classification :" + " Extreme Obesity");
}
}
//=====================================================================================================================
// Here is the Optimized way of doing the same code #Method 2
/*
import java.util.Scanner;
public class BmiCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Input weight in kilograms: ");
double weight = sc.nextDouble();
System.out.print("Input height in meters: ");
double height = sc.nextDouble();
double BMI = weight / (height * height);
System.out.println("\nThe Body Mass Index (BMI) is " + BMI + " kg/m2");
String classification;
if (BMI < 18.5) {
classification = "Under weight";
} else if (BMI <= 24.9) {
classification = "Normal";
} else if (BMI <= 29.9) {
classification = "Over weight";
} else if (BMI <= 34.9) {
classification = "Obesity (Class 1)";
} else if (BMI <= 39.9) {
classification = "Obesity (Class 2)";
} else {
classification = "Extreme Obesity";
}
System.out.println("Your BMI is: " + BMI + " kg/m2 | Classification: " + classification);
}
}
*/