Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BMICategories {
- public static void main(String[] args) {
- Scanner one = new Scanner(System.in);
- double height, weight, BMI;
- String BMICat = "";
- //remember these? comments wont do anything to the program
- System.out.print("Your height in m: "); //prints the string "your height in m:"
- height = one.nextDouble();
- //asks the user for input, in this case a rational number eg: 10, 5, 4, 1.1, 5.2, 80.343... and then stores it in a variable called height
- System.out.print("Your weight in kg: ");//prints the string "Your weight in kg:"
- weight = one.nextDouble(); //same as height but instead it stores the value in a variable called weight
- BMI = (weight / (height * height));//calculates the variable called "BMI" by dividing weight by height squared
- System.out.println(); //this will just skip a line when stuff is being printed, like pressing enter on word
- System.out.println("\nYour BMI is " + BMI + " ");
- //skips a line and prints "Your BMI is" plus the value that is returned when BMI is calculated
- if (BMI < 18.5) {//if BMI is less than 18.5 then it assigns "underweight" to the string BMIcat
- BMICat = "underweight";
- }
- if (BMI >= 18.5 && BMI < 24.9) {//same thing but instead it assigns "normal weight" to BMICat
- BMICat = "normal weight";
- }
- if (BMI >= 25.0 && BMI < 29.9) {//same thing etc...
- BMICat = "overweight";
- }
- if (BMI > 30.0) {//etc etc...
- BMICat = "obese";
- }
- System.out.println("BMI Category: " + BMICat + " ");//prints "BMI Category: " plus the string that was assigned to BMICat
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment