File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ // BMI CALCULATOR USING JAVA - FIRST OPEN SOURCE CONTRIBUTION THROUGH THIS PROJECT
2+
3+ import java .util .Scanner ;
4+
5+ public class BMICalculator {
6+ public static void main (String [] args ) {
7+ // This program calculates BMI based on user input
8+
9+ Scanner scanner = new Scanner (System .in );
10+
11+ System .out .println ("Welcome to the BMI Calculator!" );
12+
13+ // Get weight from user
14+ System .out .print ("Please enter your weight in kilograms: " );
15+ double weight = scanner .nextDouble ();
16+
17+ // Get height from user
18+ System .out .print ("Please enter your height in meters: " );
19+ double height = scanner .nextDouble ();
20+
21+ // Calculate BMI
22+ double bmi = weight / (height * height );
23+
24+ // Print the result
25+ System .out .printf ("Your BMI is: %.2f\n " , bmi );
26+
27+ // Interpret the BMI value
28+ if (bmi < 18.5 ) {
29+ System .out .println ("You are underweight." );
30+ } else if (bmi >= 18.5 && bmi < 25 ) {
31+ System .out .println ("You have a normal weight." );
32+ } else if (bmi >= 25 && bmi < 30 ) {
33+ System .out .println ("You are overweight." );
34+ } else {
35+ System .out .println ("You are obese." );
36+ }
37+
38+ // Close the scanner
39+ scanner .close ();
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ # BMI Calculator
2+
3+ This is a simple Java program that calculates your Body Mass Index (BMI) based on your weight and height.
4+
5+ ## How to Run
6+
7+ 1 . Make sure you have Java JDK 21 installed.
8+ 2 . Open a terminal in this folder.
9+ 3 . Compile the program:
10+ ```
11+ javac BMICalculator.java
12+ ```
13+ 4 . Run the program:
14+ ```
15+ java BMICalculator
16+ ```
17+
18+ ## What It Does
19+
20+ - Asks you for your weight (in kilograms) and height (in meters)
21+ - Calculates your BMI
22+ - Tells you if you are underweight, normal, overweight, or obese
23+
24+ ## JDK Version
25+
26+ - OpenJDK Runtime Environment Temurin-21 (or any OpenJDK 21)
27+
28+ ## IDE Used
29+
30+ - Visual Studio Code (VS Code)
31+
32+ ---
33+
34+ * This project was created as a beginner contribution for the Grow-with-Open-Source/Java-Projects repository.*
You can’t perform that action at this time.
0 commit comments